activerecord - rails fields_for object is nil, when I try to access an attribute -


have 3 models:

class offer < activerecord::base    has_many :offer_items end  class offeritem < activerecord::base   belongs_to :offer   belongs_to :partner_product   accepts_nested_attributes_for :partner_product end  class partnerproduct < activerecord::base  has_many :offer_items  accepts_nested_attributes_for :offer_items end 

in form offer edited, there fields_for edit offer_item

<% f.fields_for :offer_items |offer_item_form| -%>  <div class='offer_item'>    <%= render :partial => 'offer_item_fields', :locals => {:offer_item_form => offer_item_form}%>       </div> <% end -%> 

the code chunk in partial:

<%= offer_item_form.object.partner_product.name%> 

throws error

undefined method `name' nil:nilclass

extracted source (around line #29):

<%= offer_item_form.object.partner_product.name%> 

but when don't ask name, this

<%= offer_item_form.object.partner_product%> <%= debug( offer_item_form.object.partner_product)%> 

get in browser:

#<partnerproduct:0x007fa8785ff938>  --- !ruby/activerecord:partnerproduct  attributes:  id: 1 partner_id: 586 name: stock_volume: 0 source_price: 0 created_at: 2012-05-31 14:05:47 z updated_at: 2012-05-31 14:05:47 z 

i'm not wondering, why can't access 'name' attribute , changed partner_product nil, should show it. welcome! thanks


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -