I’ve got two models: a quote model and a quote line model. I’d like to be able to allow the user to create a new quote and 10 quote lines using the same form (in the future, I would like to make this number flexible using ajax).
How do I use the form helper to allow me to do this. This is what I have so far:
- for i in (1..10)
%p
= label :quote_line, :description
= text_field :quote_line, :description
= label :quote_line, :hours
= text_field :quote_line, :hours
The problem is that the labels and text fields are named exactly the same and only the last set are coming through to the params array.
I thought about adding ‘i’ on to the end of the id and name attributes, but that doesn’t seem like a clean solution.
I believe you want a nested form:
http://archives.ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
http://railscasts.com/episodes?utf8=%E2%9C%93&search=nested+forms