2

I want to create multiple instances of the same object in one form. I have tried

<%= form_tag(animals_path) do %>
 <% @animals.each do |animal| %>
  <%= fields_for "animals[]",animal do |f| %>
   `//animal fields
 <% end %>
<%= submit_tag 'save' %>`

but got error: "undefined method `merge!' for nil:NilClass"

I have built @animals at my controller like this

@animals = []
 3.times do |t|
 @animals << Animal.new
end

using rails 3.0.7

any help is appreciated.

gyohannes
  • 101
  • 1
  • 8

1 Answers1

1

I think this is not possible with nested form you can use your own trick to do this. There is some questions on stack overflow like this How to submit multiple, duplicate forms from same page in Rails - preferably with one button

Community
  • 1
  • 1
Pardeep Saini
  • 2,084
  • 1
  • 18
  • 29