2

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 
     self.city.update_attributes(:environ_rating, @hold)
end

end

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.