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
.
精彩评论