私は家主モデルを持っています。テーブルにはlisting_agent_idのフィールドがあります。また、すべての情報が保存されているエージェントモデルもあります。インデックスビューで私は<%= landlord.listing_agent.name
を試していますが、エラーが続いています。私は自分の家主のコントローラにエージェントを定義しましたが、それでもまだ機能していないようです。どんな助けもありがとう。NoMethodError - 未定義メソッド - Rails 4のIDから名前を引き出す
家主インデックス:
<tbody>
<% @landlords.each do |landlord| %>
<tr>
<td><%= landlord.listing_agent.name %></td>
</tr>
<% end %>
</tbody>
地主コントローラー:
def index
@landlords = Landlord.all
end
def new
@landlord = Landlord.new
@agents = Agent.employees.order(first_name: :asc)
end
家主モデル:
class Landlord < ActiveRecord::Base
has_many :landlord_addresses
end
エラー: