2017-01-02 4 views
-1

私はjquery raty gemを使用しています。ユーザ名の下に各ユーザの評価を追加したいと思います。私は以下の終了を置くことによって、ループを閉じるために試してみたRails jquery raty show usernameのユーザー名の上に

<div class="row"> 
 
\t \t <div class="col-md-12"> 
 
\t \t \t <div class="ratings"> 
 
\t \t \t \t <h1> Ratings </h1> 
 
\t \t \t \t <% @product.ratings.each do |rating| %> 
 
\t \t \t \t <em> User: </em><%= User.find(rating.user_id.to_i).username.capitalize %> 
 
\t \t \t \t <% end %> 
 
\t \t \t \t <%= render @product.ratings %> 
 
\t \t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t <div>

<!-- What I see is the following: --> 
 

 
Username1: Username2: 
 
(stars rating1) 
 
(stars rating2) 
 

 
<!-- And I want this: --> 
 

 
Username1: 
 
(stars rating1) 
 
Username2: 
 
(stars rating2)

:これは私がproducts.showのhtml.erbに持っているものですrender @ product.ratingsしかし、私はすべての評価を2回表示します。

答えて

0

私はそれを各インデックスを使って行った。だから、コードは次のとおりです。

<div class="row"> 
 
\t \t <div class="col-md-12"> 
 
\t \t \t <div class="ratings"> 
 
\t \t \t \t <h1> Ratings </h1> 
 
\t \t \t \t <% @product.ratings.each.with_index do |rating, index| %> 
 
\t \t \t \t <em> User: </em><%= User.find(rating.user_id.to_i).username.capitalize %> 
 
\t \t \t \t <%= render @product.ratings[index] %> 
 
\t \t \t \t <% end %> 
 
\t \t \t \t \t 
 
\t \t \t \t <div>

関連する問題