ruby-on-rails - Controller 中的 ROR + NoMethodError(尝试调用私有(private)方法)

标签 ruby-on-rails ruby ruby-on-rails-3

在我的代码中“

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/

相关文章:

ruby-on-rails - Rails 3.2.6 布线错误

ruby-on-rails - 用于多个单词的 ruby​​ 正则表达式有条件地匹配

ruby - 在使用 ruby​​ 抓取过程中提交登录字段?

ruby - 我们如何删除 RVM Default?

ruby-on-rails-3 - 编写 Mechanize 的缓存版本

ruby-on-rails-3 - Rails wrap_parameters vs include_root_in_json,有什么区别?

ruby-on-rails - 使用 STI 查询数据库的效率

ruby-on-rails - rails 3.2.x 到 rails 4.2 升级 : HTTP_COOKIE issue in request

ruby-on-rails - 使用英语语言环境时出现奇怪的 path_helper 错误

ruby-on-rails - 为有经验的开发人员简要介绍 Ruby on Rails?