0
<% @blog.blog_comment_types.each do |blog_comment_type| %>
<tr>
    <td><%= blog_comment_type.comment_type_id %></td>
        <td>Comment name goes here</td>
    </tr>
<% end %>

comment_type_id に基づいてコメント名を出力できるようにしたい。

blog_comment_type テーブルをループして、「comment_type_id」列を使用して、次のテーブルからプルできるようにしたい: 出力したい名前フィールドを持つ comment_type。comment_type テーブルには、ループされる参照された comment_type_id である ID があります。

ビュー内でそうするためのRailsのベストプラクティスはありますか?

Tbl: comment_type フィールド:

  • ID
  • 名前

tbl: blog_comment_type

田畑:

  • ID
  • comment_type_id (これは、comment_type テーブル内の一致する ID です)。

ありがとう!

4

1 に答える 1