Multiple objects from an add form

Dan Langevin wrote:

I am trying to create multiple objects from the same "add" form

For example:

Say I have a page where I want to add two movies, I have currently tried

<input type="text" name="movie[0][name]">

<input type="text" name="movie[1][name]">

The problem comes in the controller. The keys (0 and 1) are passed as Symbols and I get an error saying

"Symbol as array index"

when I try

for movie in @params[:movie]
  Movie.create(movie)
end

Try: for movie in params[:movie].values

Dan,

Have you tried using a <%= text_field("movie[]", "name") %> tag?
(Notice the square brackets after the object name). The resulting
html, when submitted, maps to a params object that contains a hash of
hashes. You can then use the following code to do an update:

Movie.update(params[:movie].keys, params[:movie].values)

If you own the AWDWR book, it's documented in a sidebar called "Forms
Containing Collections" in chapter 17.

Hope it helps,

-Anthony