Tag: 评级系统

Ruby on Rails:无法实现星级评分系统

我正在尝试为我的应用添加一个简单的星级评分系统,并以此教程为例。 我有用户,酒店和评级模型。 依赖关系是: (rating.rb) belongs_to :user belongs_to :hotel (hotel.rb)&(user.rb) has_many :ratings 并在酒店视图中使用以下代码我收到此错误: 酒店#show中的NameError 类的未定义局部变量或方法`user’… (在<%= form_for …行中) 酒店景观 (show.html.erb): {:id => form_id, :class => “star_rating_form”} do |f| %> @hotel.id %> current_user.id %> form_id + “_stars” %> <li class="rating_star" id="_” data-stars=”” data-form-id=””> 评级控制器是: def create end def update end def rating_params params.require(:rating).permit(:stars) end 迁移文件是: create_table :ratings […]

Ajaxified Star Rating System未正确更新

我使用本教程实施了星级评分系统 http://eighty-b.tumblr.com/post/1569674815/creating-an-ajaxified-star-rating-system-in-rails-3 Ajax完美运行,直到我添加Javascript,提交表单/在给定用户进行更改后保存数据。 出于某种原因,它将遍历我的索引页面上的所有元素,并在所选对象上提交正确的整数值,但随后在其余部分上提交一堆NIL值。 我只希望它更新那个ONE对象。 ( 如何在Javascript中提交相应的图书ID? ) 新的铁路请帮助:) VIEWS index.hrml.erb(书籍) <table id="book”> #####This is my partial for my form ‘ratings/rating’, :locals =>{:book => book} %> _rating.html.erb Avg. Rating { :class => ‘rating_ballot’ }, :remote => true do |f| %> “rating”, :id=>”1″}) %> ‘rating_button’) %> “rating”, :id=>”2″}) %> ‘rating_button’) %> “rating”, :id=>”3″}) %> ‘rating_button’) %> […]

Ruby on Rails显示半个星级的小数等级,例如4.5

我可以查看5个星号,一个产品的评级为5,等级为4的4个星号等。但我想做的是用我的资产中的星星图像替换星号/图像/目录,如果评级为4.5,则显示半个星。 有办法做到这一点吗? 下面是我在application_helper.rb中的当前代码和index.html.erb中的视图。 application_helper.rb: module ApplicationHelper def render_stars(value) output = ” if (1..5).include?(value.to_i) value.to_i.times { output += ‘*’} end output end end index.html.erb: Star rating: