I am trying to display this object in my view
---
- !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
fi开发者_运维百科nish_date:
attributes_cache: {}
I thought you would access start_date by doing
<% @customers.each do |customer| %>
<%= customer.histories.start_date %>
<% end %>
but I get
undefined method `start_date'
This is the find i used
@customers = Customer.find(:all,
:conditions =>['customers.id IN (?)', intersection],
:include => :histories
)
whats am I doing wrong ?
Thanks
customer.histories
is an array of History
objects, so you want something like this:
<% @customers.each do |customer| %>
<%= customer.histories.first.start_date %>
<% end %>
精彩评论