diff --git a/app/helpers/rating_engine/ratings_helper.rb b/app/helpers/rating_engine/ratings_helper.rb index 853c817..9a2da5b 100644 --- a/app/helpers/rating_engine/ratings_helper.rb +++ b/app/helpers/rating_engine/ratings_helper.rb @@ -1,7 +1,8 @@ module RatingEngine module RatingsHelper def star_rating_for(rateable, params={}) - enabled, show_score = params[:enabled].nil? ? true : params[:enabled], (params[:show_score] || true) + enabled = params[:enabled].nil? ? true : params[:enabled] + show_score = params[:show_score] || true current_score = show_score ? score_in_pixels(rateable.average_rating) : 0 render :partial => 'rating_engine/ratings/star_rating', @@ -10,15 +11,21 @@ def star_rating_for(rateable, params={}) end def score_in_pixels(current_score) - ((current_score * 125.0)/RatingEngine.max_score).round + (current_score * RatingEngine.star_length).round end def rating_url(rateable) - if rateable.rated_by?(controller.current_user) + if current_user.nil? + "" + elsif rateable.rated_by?(controller.current_user) eval("#{rateable.class.to_s.downcase}_rating_path(#{rateable.id})") else eval("#{rateable.class.to_s.downcase}_ratings_path(#{rateable.id})") end end + + def star_left_padding(score) + score_in_pixels(score) - RatingEngine.star_length + end end -end \ No newline at end of file +end diff --git a/app/views/rating_engine/ratings/_star_rating.html.erb b/app/views/rating_engine/ratings/_star_rating.html.erb index 81666b0..814d18d 100644 --- a/app/views/rating_engine/ratings/_star_rating.html.erb +++ b/app/views/rating_engine/ratings/_star_rating.html.erb @@ -5,11 +5,11 @@ <% if enabled %> <% (RatingEngine.min_score..RatingEngine.max_score).each do |score| %>