Sha256: 3e591f74211fbca5b4c76498fa70d19c12d13e22e468ff319039c9c839e27309

Contents?: true

Size: 815 Bytes

Versions: 2

Compression:

Stored size: 815 Bytes

Contents

class Review < ActiveRecord::Base
  belongs_to :product, :counter_cache => true
  has_many   :feedback_reviews

  validates_presence_of :title, :review
  validates_numericality_of :rating, :only_integer => true
  default_scope order("reviews.created_at DESC")
  scope :approved,  where("approved = ?", true)
  scope :not_approved, where("approved = ?", false)

  scope :approval_filter, lambda {|*args| {:conditions => ["(? = ?) or (approved = ?)", Spree::Reviews::Config[:include_unapproved_reviews], true, true ]}}

  scope :oldest_first, :order => "created_at asc"
  scope :preview,      :limit => Spree::Reviews::Config[:preview_size], :order=>"created_at desc"

  def feedback_stars
    return 0 if feedback_reviews.count <= 0
    ((feedback_reviews.sum(:rating)/feedback_reviews.count) + 0.5).floor
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_reviews-0.50.1 app/models/review.rb
spree_reviews-0.50.0 app/models/review.rb