In my code "
NoMethodError (Attempt to call private method): app/controllers/project_evaluations_controller.rb:94:in 开发者_如何学运维`calculate'"
occurs. SampleCode : For Controller :: Index & Show Method is not mentioned.
class ProjectEvaluationsController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:index, :show]
def calculate
@project_id = params[:id]
@costs_last_calculated = Time.now.utc
@total_internal_hours = 10
@total_external_hours = 20
@project_evaluation.update(:internal_hours => @total_internal_hours, :external_hours => @total_external_hours, :costs_last_calculated => @costs_last_calculated)
render :action=>"show"
end
end
Routes :
resources :project_evaluations do
match "calculate", :on => :collection
end
Suggest any solution !!!
update
is a private method for Active Record objects in Rails. You want to use update_attributes
instead.
Where does @project_evaluation come from? Is the update
method there something you defined? That doesn't exist as a method on instances of ActiveRecord (at least publicly) so it's possible it thinks you are trying to call a private method of that name, defined in ActiveRecord::Base somewhere. That's the main thing I see that's going on in there that looked wrong. I would change it to @project_evaluation.update_attributes()
instead.
精彩评论