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