0
我有一個房東模型,在表中有一個listing_agent_id字段。還有一個代理模型,其中存儲了所有的信息。在索引視圖中,我試圖給我們<%= landlord.listing_agent.name
,但不斷收到錯誤。我在我的landlords_controller中定義了代理,但它似乎仍然沒有工作。任何幫助,將不勝感激。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
錯誤: