Multi form for_

Hi, I am a newbie in Rails and need a lot of help for my upcoming
project for my scientific laboratory
for the basics on my application creation.
I have to create a form which includes Batches and Samples.
General idea would be Batches having (date received,
group_leader:string, contact_person:string, batch_comment and num_of
Samples:integer) . N.B batches have many samples.
now the Samples include ( Sample_name, Species, sample_type, ini_conc,
ini_vol, and sample_comment).
Now as these are of one to many relationships, I have created a form
after following many tutorials having a page showing batch detail
entry as well as asking for how many samples it involved in each
batch. After the user types in (for eg. 3), the form generates three
fields having sample details (also including name, species, type,
conc, vol, etc.) but I was not able to send these details to the
database. The only thing that updates the database is one sample
information.
my view looks something like this :

New sample

<% form_for(sample) do |f| %> <% ([email protected]_no).each do |i| -%> <%= f.error_messages %>

<%= f.hidden_field :batch_id %>

<%= f.label :sample_name %>
<%= f.text_field :sname %>

<%= f.label :organism %>
<%= f.text_field :organism, :rows => 2 %>

<%= f.label :sample_type %>
<%= f.select(:samp_type, %w{ DNA RNA}) %>

<%= f.label :ini_conc %>
<%= f.text_field :ini_conc %>

<%= f.label :ini_vol %>
<%= f.text_field :ini_vol %>

<%= f.label :storage_space %>
<%= f.text_field :storage_space %>

<%= f.label :samp_comment %>
<%= f.text_area :samp_comment, :rows => 3 %>

<% end -%>

<%= f.submit 'Submit' %>

<% end %> ## I haven't done anything much with my controller. (in fact I have no idea which controller I should add codes to) meaning I have created two scaffolds, one for batch and one for samples. and I have made a partial of the samples_view_new.html.erb and saved it in the batch_view folder which gives me an opportunity to add samples in the show_html.erb of the batch. Please could someone help me with this thing. its breaking my head a lot. Thanks in advance

Check out this RailsCast

On Jun 22, 2011, at 12:16 AM, Chirag S. wrote:

Check out this RailsCast -
#196 Nested Model Form Part 1 - RailsCasts
It will get your concepts right, the syntax will need to change a
little bit because that was for Rails 2

I just worked through this last night, there were only a few changes,
mostly to do with the <%= in the form builder view and removing the
h() from the helper (which caused double-encoding). Everything else
just worked.

Walter