调用update_attributes时未定义的方法`stringify_keys'?

chi*_*ief 2 ruby-on-rails

我收到此错误:未定义方法`stringify_keys':environ_gross_score:当我尝试创建新评级时的符号.

  class Rating < ActiveRecord::Base
  belongs_to :city


  after_save :calculate_rating


 def calculate_rating
     @env  =   self.environ

     self.city.environ_vote_count += 1                                  
     @c = self.city.environ_gross_score
     @gross = @c += @env
     self.city.update_attributes(:environ_gross_score, @gross )
     @hold = self.city.environ_gross_score / self.city.environ_vote_count 
     self.city.update_attributes(:environ_rating, @hold)
end

end
Run Code Online (Sandbox Code Playgroud)

num*_*407 7

update_attributes采用单个哈希,而不是2个参数.将行更改为:

 self.city.update_attributes(:environ_gross_score => @gross)
Run Code Online (Sandbox Code Playgroud)

发生错误是因为该方法假定传递的第一个参数是一个哈希,它(在Rails中)响应stringify_keys.