Topic: Multi-Model value storage

Hi,

I am trying to create an application with multiple models that are nested within each other. Details of the models are:

1. Study has_many samples

2. Sample has_many experiments

3. Experiment has_one run.

Now, What I would like to achieve here is multi (wizard) kind form that allows users to fill in their details step by step. For eg.

When a User clicks add study details, he is taken to a page to add a set of details regarding an study.
Then when he clicks next, He gets a page that displays him all the Samples he had submitted in the first place. He selects some samples and a form is rendered allowing him to add sample details. I

I am able to achieve till that, and have used ryans edit_multiple_individually to achieve the goal. But I am stuck after this step.

For the same samples(sample_ids) I would like to allow the user to fill in Experiment details and run details which are associated with samples but I am unable to pass the ids through the form as it all ends at the create action.

My codes are as follows.

I am trying to get this working but dont know where I am making a mistake. I have a list of samples for the user to select and add extra details to it.

def sample_list
    @samples = Sample.all
end
Sample_list.html.erb

<% form_tag add_sample_details_samples_path do %>

<table>
    <tr>
        <th></th>
        <th>Sample Name</th>
        <th>Organism</th>
        <th>Batch Name</th>
        <th>Read Number</th>
    </tr>
<% for samp in @samples %>
<% if current_user.id == samp.batch.user_id %>
    <tr>
        <td><%= check_box_tag "sample_ids[]", samp.id %></td>
        <td><%= samp.name %></td>
        <td><%= samp.organism %></td>
        <td><%= samp.batch.name %></td>
        <td><%= samp.read_no %> million</td>
    </tr>
<% end %>
<% end %>
</table>



<table>
    <tr>

        <td><%= submit_tag "Add Samples Details" %></td>
        <td></td>
    </tr>
</table>
<% end %>
When the user selects the samples and adds details to it, I would like to also create specific Experiment attributes pertaining to those samples selected.

hence

def add_sample_details
@samples = Sample.find(params[:sample_ids])
@samples.each do |sample|
  sample.expts.build
end
end
my add_sample_details view looks like this

<% form_tag create_sample_details_samples_path, :method => :put do %>
    <% for sample in @samples %>
        <% fields_for "samples[]", sample do |f| -%>
            <fieldset>
                <legend>Sample Name: <%= sample.name %></legend>
                <p><center><%= f.label :sample_title %>
                <%= f.text_field :sample_title, :size => 25 %></center></p>

            <fieldset>
                <legend>Experiment Details</legend>
                    <% f.fields_for :expts do |f_expt| %>
                    <table>
                        <tr>
                            <td><%= f_expt.label :experiment_title  %>
                                <%= f_expt.text_field :expt_title, :size => 15 %></td>
                            <td><%= f_expt.label :design_description %><br />
                                <%= f_expt.text_area :design_descrp %></td>
                        </tr>

                    </table>

            </fieldset>
        <% end %>
    <% end %>

    <p><center><%= submit_tag "Next" %></center></p>

<% end %>
But when I submit my form I get the error message as "Couldn't find Samples with ID=expts_attributes".

my create_samples_action is

def create_sample_details
    @samples = Sample.update(params[:samples].keys, params[:samples].values).reject { |p| p.errors.empty? }
     if @samples.empty?
        flash[:notice] = "Sample details taken"
        redirect_to index
      else
        render :action => "add_sample_details"
      end
  end

All suggestions are appreciated.