Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Incorrect input name with nested fields_for

#181
form_for('post[]', @post) do |f|
  f.fields_for('comment[]', @comment) do |c|
    c.text_field(:name)
  end
end

I expect:

<input name="post[123][comment][][name]" .../>

Instead I get:

<input name="post[][comment[]][name]" .../>

Reported by David Röthlisberger · May 13th, 2008 @ 04:36 PM

State: duplicate
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. David Röthlisberger
  2. josh
    josh
    • Milestone set to 2.x
    • Assigned user set to josh
    • Tag set to actionpack

    I think that should be the correct behavior. Can you get me a fix too. If not, I'll try to tackle it as well.

    July 17th, 2008 @ 01:36 AM

  3. David Röthlisberger
    David Röthlisberger

    I am swamped under at the moment, and the rails internals are still black magic to me, so it'll be at least a month before I get around to trying to fix it.

    If you can tackle it go ahead, I appreciate it. :)

    In the meantime I have worked around the problem by specifying the input name manually, i.e.

    fields_for('post[123][comment][]')

    instead of

    f.fields_for('comment[]')

    July 17th, 2008 @ 02:01 AM

  4. josh
    josh

    The state of form helpers like this feels very hackish.

    I think we should analysis some current patterns and refactor it all.

    July 19th, 2008 @ 01:45 AM

  5. Clemens Kofler
    Clemens Kofler

    Joshua: I've started refactoring the helpers in my Rails fork at github.com/clemens/rails. There's also a topic in the mailing list (http://groups.google.com/group/r...).

    FormHelper is definitely on my list, too. There's also relevant topics here and here

    July 19th, 2008 @ 11:46 AM

  6. RSL
    RSL

    There's been some changes to how index is handled as well. http://rails.lighthouseapp.com/p... has test coverage for indexes on the fields_for. Might be good to mix that in too?

    July 19th, 2008 @ 01:10 PM

  7. josh
  8. bingbing