在Controller中ROR + NoMethodError(尝试调用私有方法)

Rub*_*ist 3 ruby ruby-on-rails ruby-on-rails-3

在我的代码中"

NoMethodError(尝试调用私有方法):app/controllers/project_evaluations_controller.rb:94:在`calculate'中

发生.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
Run Code Online (Sandbox Code Playgroud)

路线:

  resources :project_evaluations do
      match "calculate", :on => :collection
    end
Run Code Online (Sandbox Code Playgroud)

建议任何解决方案!

Rya*_*igg 15

update是Rails中Active Record对象的私有方法.你想要update_attributes改用.