Wish list: form helpers for collections of new_record?s

Wes Gamble wrote:

Based on this from AWDWR 2nd ed.:

"If you need to edit multiple objects from the same model on one form, add open and closed brackets to the name of the instance variable you pass to the form helpers. This tells Rails to include the object’s id as part of the field name. For example, the following template lets a user alter one or more image URLs associated with a list of products."

Wouldn't it be nice if you could do this kind of thing to _non-saved_ model objects (which don't have ids yet) as well? Maybe the open/closed brackets could indicate to include the index of the object in the collection if the object were a new_record? and then you could more easily update attributes on the objects in that collection.

You can do this easily with the :index option. e.g.

<% @collection.each_with_index do |@item, i| %> <%= text_field :item, :method1, :index => i %> <%= text_field :item, :method2, :index => i %> <% end %>

posts params

{:item => {1 => {:method1 => 'a', :method2 => 'b'},             2 => {:method1 => 'c', :method2 => 'd'}}}

You can also use square brackets to get automatic indexing of form fields into param arrays:

<% @collection.each do |item| %> <%= text_field_tag 'item[method1]', item.method1 %> <%= text_field_tag 'item[method2]', item.method2 %> <% end %>

posts params

{:item => {:method1 => ['a', 'c'], :method2 => ['b', 'd']}}