I've a model called Rating that reference itself.
class Rating < ActiveRecord::Base
has_many :ratings, :as => :ratable, :dependent => :destroy
after_save :update_total_rating
private
def update_total_rating
return true unless value_changed?
rating_sum = Rating.sum('value',
:conditions =>["ratable_id = ? and ratable_type = ?",
self.ratable_id, self.ratable_type])
ratable.update_attribute(:total_rating, rating_sum)
return true
end
end
I am doing this to cache the total rating on a rating. This is working perfectly on development and updating the total_rating, it's also working on production when I do a model save on rating in Heroku Rails Console (heroku run rails c), but this is not working when executed through the web app hosted on Heroku, it seems that update_total_rating is not being called for some reason.
Any idea what could be causing this or how to fix this?
Thanks