3

自分自身を参照する Rating というモデルがあります。

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

評価の合計評価をキャッシュするためにこれを行っています。これは、開発と total_rating の更新で完全に機能しています。Heroku Rails コンソール (heroku run rails c) でモデルの評価を保存すると、本番環境でも機能しますが、Heroku でホストされている Web アプリを介して実行すると機能しません。 update_total_rating が何らかの理由で呼び出されていないようです。

これを引き起こしている可能性のあるもの、またはこれを修正する方法はありますか?

ありがとう

4

0 に答える 0