开发者

Undefined method `stringify_keys' when calling update_attributes?

开发者 https://www.devze.com 2023-04-07 14:06 出处:网络
I am getting this error: undefined method `stringify_keys\' for :environ_gross_score:Symbol when I attempt to create a new rating.

I am getting this error: undefined method `stringify_keys' for :environ_gross_score:Symbol when I attempt to create a new rating.

  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 
     开发者_JS百科self.city.update_attributes(:environ_rating, @hold)
end

end


update_attributes takes a single hash, not 2 parameters. Change the line to:

 self.city.update_attributes(:environ_gross_score => @gross)

The error was happening because the method assumed that the first argument passed was a hash, which does (in Rails) respond to stringify_keys.

0

精彩评论

暂无评论...
验证码 换一张
取 消