Skip to content

Commit

Permalink
fix ajax update where there are no dimensions, and using big stars
Browse files Browse the repository at this point in the history
  • Loading branch information
bbwharris authored and edgarjs committed May 29, 2010
1 parent db13aaa commit caa3b01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ajaxful_rating.gemspec
Expand Up @@ -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"]
Expand Down
28 changes: 14 additions & 14 deletions lib/axr/model.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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+
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit caa3b01

Please sign in to comment.