在我的代码中“
NoMethodError (Attempt to call private method): app/controllers/project_evaluations_controller.rb:94:in `calculate'"
发生。 SampleCode : For Controller::Index & Show 方法未提及。
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
路线:
resources :project_evaluations do
match "calculate", :on => :collection
end
建议任何解决方案!!!
最佳答案
update
是 Rails 中 Active Record 对象的私有(private)方法。您想改用 update_attributes
。
关于ruby-on-rails - Controller 中的 ROR + NoMethodError(尝试调用私有(private)方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5294596/