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 ?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/uuu0qyyW8l8J.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Mar 1, 2012 at 1:22 pm

    On 29 February 2012 12:33, Antoine Herzog wrote:
    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 ?
    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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 1, '12 at 12:43p
activeMar 1, '12 at 1:22p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Colin Law: 1 post Antoine Herzog: 1 post

People

Translate

site design / logo © 2021 Grokbase