Module: RailsRateable::ClassMethods
- Defined in:
- lib/app/models/rails_rateable.rb
Instance Method Summary collapse
-
#acts_as_rateable(options = {}) ⇒ Object
put class method here to be trigger as say User.method_name.
- #find_top_rated(params = {}) ⇒ Object
Instance Method Details
#acts_as_rateable(options = {}) ⇒ Object
put class method here to be trigger as say User.method_name
10 11 12 13 14 15 |
# File 'lib/app/models/rails_rateable.rb', line 10 def acts_as_rateable( = {}) unless respond_to?(:max_rating) class_attribute :max_rating self. = [:max_rating] || 5 end end |
#find_top_rated(params = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/app/models/rails_rateable.rb', line 17 def find_top_rated(params = {}) find_params = params.merge(:include => :rating) find_params[:order] = ['ratings.average_rating DESC', find_params.delete(:order)].compact.join(", ") find_params[:limit] = 20 unless find_params.key?(:limit) find(:all, find_params) end |