显示个人用户评分(letsrate gem) [英] Displaying Individual User Ratings (letsrate gem)
问题描述
我目前在我的应用中使用了 letrate gem (https://github.com/muratguzel) 并且评级显示正确.
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.
详细信息:rating_for"助手仅显示来自一组用户的平均评分,但我希望能够同时显示用户提交的个人评分(而不是平均值).例如,用户 A 可能为某个维度提交 2 星评级,而用户 B 可能为同一维度提交 4 星评级.rating_for"助手将显示 3 星的平均评分,但我无法显示用户 A 和用户 B 的个人评分.
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.
推荐答案
希望对您有所帮助:
请在helper中添加这个方法:-
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
谢谢
这篇关于显示个人用户评分(letsrate gem)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!