Sha256: 6eadbfe6dbf3101b574d3028023280f63a79c981b1ab813928117a4cfb3e26b5
Contents?: true
Size: 423 Bytes
Versions: 2
Compression:
Stored size: 423 Bytes
Contents
# Add access to reviews/ratings to the product model Product.class_eval do has_many :reviews def get_stars [avg_rating.round, reviews_count] end def recalculate_rating reviews_count = reviews.approved.count if reviews_count > 0 self.update_attribute :avg_rating, self.reviews.approved.sum(:rating).to_f / reviews_count else self.update_attribute :avg_rating, 0 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spree_reviews-0.50.1 | app/models/product_decorator.rb |
spree_reviews-0.50.0 | app/models/product_decorator.rb |