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.

Enhancement on nested forms: send params as array

#5395

I was looking at this post on Rails Forum:
http://railsforum.com/viewtopic.php?id=28447

And tried to create something more simple. The best I came was to rename the text_field's name property, so my "task" partial was:

<%= f.hidden_field :id, :name => 'project[tasks_attributes][][id]' %>
<%= f.label :name %>
<%= f.text_field :name, :size => 15, :name => 'project[tasks_attributes][][name]' %>

It works as a charm. On older versions of Rails, if I named an input like 'project[][name]' the result would be a little strange, but right now it sends an array of hashes, as one would expect.

I uploaded the example code to my github: http://github.com/mauricioszabo/Nested-Forms-example. I think that it would make more sense to generate HTML like:

  <input id="project_tasks_attributes_0_name" name="project[tasks_attributes][][name]" size="15" type="text" />
Than to generate
  <input id="project_tasks_attributes_0_name" name="project[tasks_attributes][0][name]" size="15" type="text" />
Because it have the same functionality, clutters less the code, it's more flexible to adapt (I just need to generate a static for the text_field, don't need to create a "fake unique ID"), and, right now, it doesn't need any changes on the model part, just on the Form Helper.

Reported by Mauricio Eduardo Szabo · August 17th, 2010 @ 06:48 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Andrea Campi
    Andrea Campi

    Looks like your HTML markup got lost, can you try again?

    October 18th, 2010 @ 07:20 AM

  2. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Importance changed from to Low

    Updated the ticket to show the HTML snippets. :)

    October 18th, 2010 @ 09:38 AM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:29 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:29 PM

  5. bingbing