Module: Helpers
- Included in:
- ActionView::Base
- Defined in:
- lib/letsrate/helpers.rb
Instance Method Summary collapse
- #rating_for(rateable_obj, dimension = nil, options = {}) ⇒ Object
- #rating_for_user(rateable_obj, rating_user, dimension = nil, options = {}) ⇒ Object
Instance Method Details
#rating_for(rateable_obj, dimension = nil, options = {}) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/letsrate/helpers.rb', line 2 def (rateable_obj, dimension=nil, ={}) cached_average = rateable_obj.average dimension avg = cached_average ? cached_average.avg : 0 star = [:star] || 5 disable_after_rate = [:disable_after_rate] || true readonly = !(current_user && rateable_obj.can_rate?(current_user, dimension)) content_tag :div, '', "data-dimension" => dimension, :class => "star", "data-rating" => avg, "data-id" => rateable_obj.id, "data-classname" => rateable_obj.class.name, "data-disable-after-rate" => disable_after_rate, "data-readonly" => readonly, "data-star-count" => star end |
#rating_for_user(rateable_obj, rating_user, dimension = nil, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/letsrate/helpers.rb', line 21 def (rateable_obj, , dimension = nil, = {}) @object = rateable_obj @user = @rating = Rate.find_by_rater_id_and_rateable_id_and_dimension(@user.id, @object.id, dimension) stars = @rating ? @rating.stars : 0 disable_after_rate = [:disable_after_rate] || false readonly=false if disable_after_rate readonly = current_user.present? ? !rateable_obj.can_rate?(current_user.id, dimension) : true end content_tag :div, '', "data-dimension" => dimension, :class => "star", "data-rating" => stars, "data-id" => rateable_obj.id, "data-classname" => rateable_obj.class.name, "data-disable-after-rate" => disable_after_rate, "data-readonly" => readonly, "data-star-count" => stars end |