Module: AjaxfulRating::ClassMethods
- Defined in:
- lib/ajaxful_rating_model.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#ajaxful_rateable(options = {}) ⇒ Object
Extends the model to be easy ajaxly rateable.
-
#ajaxful_rater(options = {}) ⇒ Object
Makes the association between user and Rate model.
-
#max_rate_value ⇒ Object
Maximum value accepted when rating the model.
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/ajaxful_rating_model.rb', line 13 def @options end |
Instance Method Details
#ajaxful_rateable(options = {}) ⇒ Object
Extends the model to be easy ajaxly rateable.
Options:
-
:stars
Max number of stars that can be submitted. -
:allow_update
Set to true if you want users to be able to update their votes. -
:cache_column
Name of the column for storing the cached rating average.
Example:
class Article < ActiveRecord::Base
ajaxful_rateable :stars => 10, :cache_column => :custom_column
end
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ajaxful_rating_model.rb', line 26 def ajaxful_rateable( = {}) has_many :rates_without_dimension, :as => :rateable, :class_name => 'Rate', :dependent => :destroy, :conditions => {:dimension => nil} [:dimensions].each do |dimension| has_many "#{dimension}_rates", :dependent => :destroy, :conditions => {:dimension => dimension.to_s}, :class_name => 'Rate', :as => :rateable end if [:dimensions].is_a?(Array) @options = .reverse_merge( :stars => 5, :allow_update => true, :cache_column => :rating_average ) include AjaxfulRating::InstanceMethods extend AjaxfulRating::SingletonMethods end |
#ajaxful_rater(options = {}) ⇒ Object
Makes the association between user and Rate model.
46 47 48 |
# File 'lib/ajaxful_rating_model.rb', line 46 def ajaxful_rater( = {}) has_many :rates, end |
#max_rate_value ⇒ Object
Maximum value accepted when rating the model. Default is 5.
Change it by passing the :stars option to ajaxful_rateable
ajaxful_rateable :stars => 10
55 56 57 |
# File 'lib/ajaxful_rating_model.rb', line 55 def max_rate_value [:stars] end |