繰り返しになりますが、これほど難しいことではないはずの何かに直面していますが、1時間ほど私を怒らせています。1つの「インデックス」ビューにプルしたい複数のモデルがあります。私はそれが参加だと思いますが、私はそれを行う方法を見つけることができないようです。
インデックスビューにあるもの:
<% @tips.each do |tip| %>
<tr>
<td><%= tip.user_id %></td>
<td><%= tip.city_id # here I want to draw on the cities table to show city.name
%></td>
<td><%= tip.type_id # here I want to draw on the type table to show type.name
%></td>
<td><%= tip.place_id # here I want to draw on the place table to show place.name
%></td>
<td><%= tip.tip_desc %></td>
<td><%= link_to 'Show', tip %></td>
<td><%= link_to 'Edit', edit_tip_path(tip) %></td>
<td><%= link_to 'Destroy', tip, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
モデルは次のとおりです。
class Tip < ActiveRecord::Base
belongs_to :user
belongs_to :city
belongs_to :place
end
class Place < ActiveRecord::Base
belongs_to :city
has_and_belongs_to_many :collections
has_many :tips
end
class City < ActiveRecord::Base
has_many :places
has_many :tips
end
どんな助けでも本当にありがたいです!
前もって感謝します、
ジェームズ