开发者

Using ruby object in views

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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜