Multiple Row Form similar to Milestones on BaseCamp

Hi all,

Wondering how to setup my view and controller to do something similar to
the form on Basecamp that allows adding up to 10 milestones on one page.

Thanks
Phil

On Jan 23, 2006, at 4:47 PM, Phil W. wrote:

Hi all,

Wondering how to setup my view and controller to do something
similar to
the form on Basecamp that allows adding up to 10 milestones on one
page.

The trick, Phil, is to do something like:

<% 10.times do |n| %>
<%= text_field_tag “milestones[#{n}][title]” %>

<% end %>

Then, in your controller you do:

def create
10.times do |n|
next if params[:milestones][n.to_s][:title].blank?
Milestone.create(params[:milestones][n.to_s])
end
end

Hope that makes sense,

Jamis

I’ve really got to start thinking along simpler terms! This is great.
Would extending this for multiple fields be simply checking each field
to see if it is blank or something like this?

def create
10.times do |n|
next if params[:milestones][n.to_s].empty?
Milestone.create(params[:milestones][n.to_s])
end
end

Thanks very much.
Phil

Jamis B. wrote:

On Jan 23, 2006, at 4:47 PM, Phil W. wrote:

Hi all,

Wondering how to setup my view and controller to do something
similar to
the form on Basecamp that allows adding up to 10 milestones on one
page.

The trick, Phil, is to do something like:

<% 10.times do |n| %>
<%= text_field_tag “milestones[#{n}][title]” %>

<% end %>

Then, in your controller you do:

def create
10.times do |n|
next if params[:milestones][n.to_s][:title].blank?
Milestone.create(params[:milestones][n.to_s])
end
end

Hope that makes sense,

Jamis