2011-03-14 39 views
3

在我的代码“ROR + NoMethodError(尝试调用私有方法)在控制器

NoMethodError(尝试调用私有 法): 应用程序/控制器/ project_evaluations_controller.rb:94:在 `计算'“

发生。 SampleCode:对于Controller :: Index & Show Method没有提及。

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 

推荐任何解决方案!

回答

15

update是Rails中Active Record对象的私有方法。您想用update_attributes代替。

1

@project_evaluation从哪里来?那里有你定义的update方法吗?这不是作为ActiveRecord实例的一种方法存在的(至少是公开的),所以有可能它认为你试图调用这个名字的私有方法,在ActiveRecord :: Base的某个地方定义。这是我看到那里看起来错了的主要事情。我会改为@project_evaluation.update_attributes()

相关问题