From caa3b01ba8fefe188b709bc01a77d71fe2a7286b Mon Sep 17 00:00:00 2001 From: Brandon Harris Date: Fri, 28 May 2010 00:18:02 +0800 Subject: [PATCH] fix ajax update where there are no dimensions, and using big stars --- ajaxful_rating.gemspec | 4 ++-- lib/axr/model.rb | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ajaxful_rating.gemspec b/ajaxful_rating.gemspec index 0e7b9c7..3dc4d15 100644 --- a/ajaxful_rating.gemspec +++ b/ajaxful_rating.gemspec @@ -2,11 +2,11 @@ Gem::Specification.new do |s| s.name = %q{ajaxful_rating} - s.version = "2.2.5" + s.version = "2.2.6" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= s.authors = ["Edgar J. Suarez"] - s.date = %q{2010-05-21} + s.date = %q{2010-05-27} s.description = %q{Provides a simple way to add rating functionality to your application.} s.email = %q{edgar.js@gmail.com} s.extra_rdoc_files = ["CHANGELOG", "README.textile", "lib/ajaxful_rating.rb", "lib/axr/css_builder.rb", "lib/axr/errors.rb", "lib/axr/helpers.rb", "lib/axr/locale.rb", "lib/axr/model.rb", "lib/axr/stars_builder.rb"] diff --git a/lib/axr/model.rb b/lib/axr/model.rb index 000932c..05efa9b 100644 --- a/lib/axr/model.rb +++ b/lib/axr/model.rb @@ -21,7 +21,7 @@ def ajaxful_rateable(options = {}) 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 - + options[:dimensions].each do |dimension| has_many "#{dimension}_rates", :dependent => :destroy, :conditions => {:dimension => dimension.to_s}, :class_name => 'Rate', :as => :rateable @@ -36,12 +36,12 @@ def axr_config :cache_column => :rating_average } end - + alias_method :ajaxful_rating_options, :axr_config end - + axr_config.update(options) - + include AjaxfulRating::InstanceMethods extend AjaxfulRating::SingletonMethods end @@ -54,7 +54,7 @@ def ajaxful_rater(options = {}) # Instance methods for the rateable object. module InstanceMethods - + # Proxy for axr_config singleton method. def axr_config self.class.axr_config @@ -84,11 +84,11 @@ def rate(stars, user, dimension = nil) rate.save! self.update_cached_average(dimension) end - + # Builds the DOM id attribute for the wrapper in view. def wrapper_dom_id(options = {}) options = options.symbolize_keys.slice(:small, :dimension) - options = options.select { |k, v| v.present? }.map do |k, v| + options = options.select { |k, v| v.present? or (v == false) }.map do |k, v| if k == :dimension v.to_s else @@ -106,13 +106,13 @@ def wrapper_dom_id(options = {}) def raters(dimension = nil) sql = "SELECT DISTINCT u.* FROM #{self.class.user_class.table_name} u "\ "INNER JOIN rates r ON u.id = r.rater_id WHERE " - + sql << self.class.send(:sanitize_sql_for_conditions, { :rateable_id => id, :rateable_type => self.class.base_class.name, :dimension => (dimension.to_s if dimension) }, 'r') - + self.class.user_class.find_by_sql(sql) end @@ -125,7 +125,7 @@ def rate_by(user, dimension = nil) def rated_by?(user, dimension = nil) !rate_by(user, dimension).nil? end - + # Returns whether or not the user can rate this object. # Based on if the user has already rated the object or the # :allow_update option is enabled. @@ -181,7 +181,7 @@ def update_cached_average(dimension = nil) end module SingletonMethods - + # Maximum value accepted when rating the model. Default is 5. # # Change it by passing the :stars option to +ajaxful_rateable+ @@ -195,7 +195,7 @@ def max_stars def user_class_name Rate.reflect_on_association(:rater).options[:class_name] end - + # Gets the user's class def user_class user_class_name.constantize @@ -225,13 +225,13 @@ def find_less_popular(dimension = nil) def find_statement(attr_name, attr_value, dimension = nil) sql = "SELECT DISTINCT r2.* FROM rates r1 INNER JOIN "\ "#{self.base_class.table_name} r2 ON r1.rateable_id = r2.id WHERE " - + sql << sanitize_sql_for_conditions({ :rateable_type => self.base_class.name, attr_name => attr_value, :dimension => (dimension.to_s if dimension) }, 'r1') - + find_by_sql(sql) end