Note that there are some explanatory texts on larger screens.

plurals
  1. POFind ID does not find the id and create
    primarykey
    data
    text
    <p>I have a 2 views that I want to use before the create action. </p> <p>1st view is add_sample_details.html.erb</p> <pre><code>&lt;% form_tag add_expt_details_samples_path :method =&gt; :post do %&gt; &lt;% for sample in @samples %&gt; &lt;% fields_for "samples[]", sample do |form| %&gt; &lt;fieldset&gt; &lt;legend&gt;Sample Name: &lt;%= sample.name %&gt;&lt;/legend&gt; &lt;p&gt;&lt;center&gt;&lt;%= form.label :sample_title %&gt; &lt;%= form.text_field :sample_title, :size =&gt; 25 %&gt;&lt;/center&gt;&lt;/p&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;%= form.label :taxon_id %&gt; &lt;%= form.text_field :taxon_id, :size =&gt; 15 %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= form.label :scientific_name %&gt; &lt;%= form.text_field :scientific_name, :size =&gt; 20 %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= form.label :common_name %&gt; &lt;%= form.text_field :common_name, :size =&gt; 15 %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt; &lt;center&gt; &lt;%= form.label :sample_descripition %&gt;&lt;br \&gt; &lt;%= form.text_area :description %&gt; &lt;/center&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;p&gt;&lt;center&gt;&lt;%= submit_tag "Next" %&gt;&lt;/center&gt;&lt;/p&gt; &lt;% for samp in @samples %&gt; &lt;%= hidden_field_tag("sample_ids[]", samp.id) %&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>in the SamplesController, the add_expt_details looks like this</p> <pre><code>def add_expt_details # Collect the samples that were sent @expt_samples = Sample.find(params[:sample_ids]) end </code></pre> <p>and the add_expt_details.html.erb looks like this</p> <pre><code>&lt;% form_for @expt_samples, :url =&gt; create_study_samples_path, :html =&gt; { :method =&gt; :put } do |f| %&gt; &lt;% @expt_samples.each do |samp|%&gt; &lt;% f.fields_for :expts do |form| %&gt; &lt;%= form.label :experiment_title %&gt; &lt;%= form.text_field :expt_title, :size =&gt; 15 %&gt;&lt;br \&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;p&gt;&lt;center&gt;&lt;%= submit_tag "Next" %&gt;&lt;/center&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>and my create_study action is like this</p> <pre><code>def create_study @study = Study.new(params[:study]) # this method collects all the samples from the add_sra_details view from the hidden_field_tag if current_user.id? # Put the current user_id in the study.user_id @study.user_id = current_user.id if @study.save # Save the values for the study # Update the Sample attributes @samples = Sample.update(params[:samples].keys, params[:samples].values).reject { |p| p.errors.empty? } # For all those sample_ids selected by the user, put the study ids in the sample_study_id @samples.each do |samp| @study.samples &lt;&lt; samp end # get the ids_sent from the add_expt_details @expt_samples = Sample.find(params[:id]) # A Flash message stating the details would be prefereable..! (Means you have to do it) flash[:success] = "Your Study has been Created" redirect_to add_expt_details_samples_path else flash[:error] = "Study Faulty" render :action =&gt; "add_sra_details" end end end </code></pre> <p>The error message I get when I keep the @expt_samples = Sample.find(params[:id]) is "undefined method `keys' for nil:NilClass"</p> <p>and If I dont have the @expt_samples, it gives me an error "Couldn't Find id in Sample"</p> <p>Can some one suggest how can I update set of sample ids from one form and also create new Expt model records that are associated to the sample_ids in another form.</p> <p>All suggestions are appreciated.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload