在控制器中出现ROR + NoMethodError错误(尝试调用私有方法)

3

我的代码中出现了错误:

未定义方法错误(尝试调用私有方法): app/controllers/project_evaluations_controller.rb:94:in `calculate'

样例代码:对于控制器的 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

提出任何解决方案!!!
2个回答

15

update 是 Rails 中 Active Record 对象的私有方法。你应该使用 update_attributes 方法。


1
@project_evaluation是从哪里来的?'update'方法是您定义的吗?在ActiveRecord的实例中并不存在这样的方法(至少公开),因此可能它认为您正在尝试调用该名称的私有方法,在ActiveRecord :: Base中定义。那是我看到的主要问题,看起来不正确。我会改成@project_evaluation.update_attributes()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接