views:

14

answers:

1

Hi,

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
       finish_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

A: 

customer.histories is an array of History objects, so you want something like this:

<% @customers.each do |customer| %>
  <%= customer.histories.first.start_date %>
<% end %>
Jordan
Thanks, what about if there were multiple histories would you just use a sub loop ?
Josh
Yes, that's probably what you'd want to do.
Jordan