You're making it too hard for yourself. Just do the iteration in the
controller, or make a method like "create_multiple" in your person
model.
Cheers
Starr
Here is an example to accomplish what you are trying to do. The 'show'
method starts things rolling. The 'people' table has only 'id' and
'name' columns.
The Model (person.rb):
class Person < ActiveRecord::Base
end
The Controller (person_controller.rb):
class PersonController < ApplicationController
def show
end
def nbrOfNewPeople
3
end
def add_person
nbrOfNewPeople.times do | index |
person = Person.new
personParams = params[('person' + index.to_s).intern]
person.update_attributes(personParams) unless
personParams[:name].empty?
end
end
end
The View (show.rhtml)
<%= form_tag :action=> 'add_person' %>
<% controller.nbrOfNewPeople.times do | i | %>
<label for='<%='person' + i.to_s%>'>Name:</label>
<%= text_field 'person' + i.to_s, 'name' %>
</br>
<% end %>
<%= submit_tag "Add People" %>
<%= end_form_tag %>
Paul