現状:
モデルの関係
User has_many products productテーブルのカラム product_id title
Product belongs_to user userテーブルのカラム user_id username
ビュー
ruby
1<% @product.each do |comic| %> 2 <tr> 3 <td><%= image_tag product.front_cover.to_s %></td> 4 <td><%= product.title %></td> 5 <% user.products.each do |user| %> 6 <td><%= user.username %></td> 7 <% end %>
質問:
このような時に、each文内でproductを投稿したuserのusernameを出せるようにしたいです。
ちなみに上記のviewだとundefined local variable or method `user' for #<#Class:0x007f98ac6ad320:0x007f98ae436e00>
となります。
何卒、ご教授ください。よろしくお願い申し上げます。
あなたの回答
tips
プレビュー