This project is archived and is in readonly mode.

#5395 ✓stale
Mauricio Eduardo Szabo

Enhancement on nested forms: send params as array

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

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.

Comments and changes to this ticket

  • Andrea Campi

    Andrea Campi October 18th, 2010 @ 07:20 AM

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

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer October 18th, 2010 @ 09:38 AM

    • Importance changed from “” to “Low”

    Updated the ticket to show the HTML snippets. :)

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    • State changed from “open” to “stale”
  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages