开发者

Using ruby object in views

开发者 https://www.devze.com 2023-01-10 00:10 出处:网络
I am trying to display this object in my view --- - !ruby/object:Customer attributes: country: United Kingdom

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

精彩评论

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