我正在使用jquery raty gem,我想在每个用户的用户名下面添加评级。这就是我在products.show html.erb中所拥有的:
<div class="row">
<div class="col-md-12">
<div class="ratings">
<h1> Ratings </h1>
<% @product.ratings.each do |rating| %>
<em> User: </em><%= User.find(rating.user_id.to_i).username.capitalize %>
<% end %>
<%= render @product.ratings %>
<div>
<!-- What I see is the following: -->
Username1: Username2:
(stars rating1)
(stars rating2)
<!-- And I want this: -->
Username1:
(stars rating1)
Username2:
(stars rating2)
我试图通过将结尾放在render @ product.ratings下面来关闭循环,但这样做我得到的所有评级都显示了两次。
答案 0 :(得分:0)
我做了它,使用每个索引。所以代码是:
<div class="row">
<div class="col-md-12">
<div class="ratings">
<h1> Ratings </h1>
<% @product.ratings.each.with_index do |rating, index| %>
<em> User: </em><%= User.find(rating.user_id.to_i).username.capitalize %>
<%= render @product.ratings[index] %>
<% end %>
<div>