user2448746
user2448746

Reputation: 21

Displaying Individual User Ratings (letsrate gem)

I am currently using the letsrate gem (https://github.com/muratguzel) in my app and the ratings display correctly.

However, I would like to display the rating(s) an individual user submitted instead of just displaying the average.

Details: the "rating_for" helper only displays the average rating from a collection of users but I would like to be able to display the individual ratings that the user submitted as well (not the averages). For example, User A may submit a rating of 2 stars for a dimension and User B may submit a rating of 4 stars for the same dimension. The "rating_for" helper will display an average rating of 3 stars but I cannot get the individual ratings for User A and User B to display.

Upvotes: 2

Views: 963

Answers (1)

Ankush Kataria
Ankush Kataria

Reputation: 323

Hope it will be help for you:

Please add this method in the helper:-

def rating_for_user(rateable_obj, rating_user, dimension = nil, options = {})
  @object = rateable_obj
  @user = rating_user
  @rating = Rate.find_by_rater_id_and_rateable_id_and_dimension(@user.id, @object.id, dimension)
  star = options[:star] || 5
  stars = @rating ? @rating.stars : 0

  disable_after_rate = options[: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" => star
end

Thanks

Upvotes: 1

Related Questions