lib/is_reviewable/reviewable.rb
# Update cache fields if available/enabled.
#
Update cache fields if available/enabled.
Update cache fields if available / enabled .
def update_cache!
          if self.reviewable_caching_fields?(:total_reviews)
            self.cached_total_reviews = self.total_reviews(true)
          end
          if self.reviewable_caching_fields?(:average_rating)
            self.cached_average_rating = self.average_rating(true)
          end
          self.save_without_validation if self.changed?
        end
def update_cache! if self . reviewable_caching_fields? ( :total_reviews ) self . cached_total_reviews = self . total_reviews ( true ) end if self . reviewable_caching_fields? ( :average_rating ) self . cached_average_rating = self . average_rating ( true ) end self . save_without_validation if self . changed? end
Update cache fields if available/enabled.
Update cache fields if available / enabled .
# self.cached_total_reviews += 1 if review.new_record? # new_rating = review.rating - (old_rating || 0) # self.cached_average_rating = (self.cached_average_rating + new_rating) / self.cached_total_reviews.to_f