Module: AjaxfulRating::ClassMethods
- Defined in:
- lib/axr/model.rb
Instance Method Summary (collapse)
-
- (Object) ajaxful_rateable(options = {})
Extends the model to be easy ajaxly rateable.
-
- (Object) ajaxful_rater(options = {})
Makes the association between user and Rate model.
Instance Method Details
- (Object) ajaxful_rateable(options = {})
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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/axr/model.rb', line 20 def ajaxful_rateable( = {}) has_many :rates_without_dimension, :as => :rateable, :class_name => 'Rate', :dependent => :destroy, :conditions => {:dimension => nil} has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater [:dimensions].each do |dimension| has_many "#{dimension}_rates", :dependent => :destroy, :conditions => {:dimension => dimension.to_s}, :class_name => 'Rate', :as => :rateable has_many "#{dimension}_raters", :through => "#{dimension}_rates", :source => :rater end if [:dimensions].is_a?(Array) class << self def axr_config @axr_config ||= { :stars => 5, :allow_update => true, :cache_column => :rating_average } end alias_method :ajaxful_rating_options, :axr_config end axr_config.update() include AjaxfulRating::InstanceMethods extend AjaxfulRating::SingletonMethods end |
- (Object) ajaxful_rater(options = {})
Makes the association between user and Rate model.
50 51 52 |
# File 'lib/axr/model.rb', line 50 def ajaxful_rater( = {}) has_many :ratings_given, .merge(:class_name => "Rate", :foreign_key => :rater_id) end |