我想在我的视图中显示这个对象
---
- !ruby/object:Customer
attributes:
country: United Kingdom
last_name: a
first_name: b
attributes_cache: {}
histories:
- !ruby/object:History
attributes:
start_date: 11/03/2010
finish_date:
attributes_cache: {}
我以为你会通过
来访问start_date <% @customers.each do |customer| %>
<%= customer.histories.start_date %>
<% end %>
但我得到
undefined method `start_date'
这是我使用的发现
@customers = Customer.find(:all,
:conditions =>['customers.id IN (?)', intersection],
:include => :histories
)
我做错了什么?
由于
答案 0 :(得分:0)
customer.histories
是一个History
个对象的数组,所以你想要这样的东西:
<% @customers.each do |customer| %>
<%= customer.histories.first.start_date %>
<% end %>