Both of my callback methods have update_attributes in them. So it looks like when calculate_rating runs it also calls modify_rating. I only want calculate_rating to run for creating a new record and modify_rating to run only when editing and updating a record through a form.
after_create :calculate_rating
before_update :modify_rating
def calculate_rating
end
def modify_rating
end
From the fine manual for
update_attributes:So when you call
update_attributes, it will try to save the object and that means thatupdate_attributesis not appropriate for either of the callbacks you’re using;update_attributesis meant to be used by controllers for mass assignment and the like.You could replace the
update_attributescall with simple assignments: