can t apply any method on nested form fields attributes

11 views
Skip to first unread message

Antoine Herzog

unread,
Feb 29, 2012, 7:33:09 AM2/29/12
to rubyonra...@googlegroups.com

I am using cocoon from github to deal with accepts_nested_attributes_for. In my partial i am trying to manipulate nested attributes but it is not working. My code is in my partial :

.nested-fields
 
= f.inputs do
   
= f.object.myarrayfield.length

I have an error message :

undefined method `length' for nil:NilClass

If I do only that

.nested-fields
 
= f.inputs do
   
= f.object.myarrayfield

There is no error message and the page give me the value of the field :

[1,2]

The length method should give me 2 not nil, do you know why ?

Colin Law

unread,
Mar 1, 2012, 8:21:34 AM3/1/12
to rubyonra...@googlegroups.com

It is not the length method that is giving nil, read the error
carefully. It says that you cannot call length on something that is
nil. It is f.object.myarrayfield that is nil.

Colin

Reply all
Reply to author
Forward
0 new messages