Note that there are some explanatory texts on larger screens.

plurals
  1. POSending the details of the multi form to the database
    primarykey
    data
    text
    <p>I have to create a form which includes Batches and Samples. </p> <p>General idea would be Batches having (<code>received:date</code>, <code>group_leader:string</code>, <code>contact_person:string</code>, <code>batch_comment:string</code> and <code>num_of_samples:integer</code>) .<br> N.B batches have many samples. now the Samples include ( <code>sample_name</code>, <code>species</code>, <code>sample_type</code>, <code>ini_conc</code>, <code>ini_vol</code>, and <code>sample_comment</code>).</p> <p>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 <code>name</code>, <code>species</code>, <code>type</code>, <code>conc</code>, <code>vol</code>, etc.) but I was not able to send these details to the database.<br> The only thing that updates the database is one sample information. my view looks something like this :</p> <p>New sample: </p> <pre><code> &lt;p&gt;&lt;% form_for(sample) do |f| %&gt;&lt;/p&gt; &lt;p&gt;&lt;% (1..@batch.sample_no).each do |i| -%&gt;&lt;/p&gt; &lt;%= f.error_messages %&gt; &lt;p&gt; &lt;%= f.hidden_field :batch_id %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :sample_name %&gt;&lt;br /&gt; &lt;%= f.text_field :sname %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :organism %&gt;&lt;br /&gt; &lt;%= f.text_field :organism, :rows =&gt; 2 %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :sample_type %&gt;&lt;br /&gt; &lt;%= f.select(:samp_type, %w{ DNA RNA}) %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :ini_conc %&gt;&lt;br /&gt; &lt;%= f.text_field :ini_conc %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :ini_vol %&gt;&lt;br /&gt; &lt;%= f.text_field :ini_vol %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :storage_space %&gt;&lt;br /&gt; &lt;%= f.text_field :storage_space %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :samp_comment %&gt;&lt;br /&gt; &lt;%= f.text_area :samp_comment, :rows =&gt; 3 %&gt; &lt;/p&gt; &lt;% end -%&gt; &lt;p&gt;&lt;%= f.submit 'Submit' %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>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 <code>show_html.erb</code> of the batch.</p> <p>my models of <code>batch.rb</code> and <code>sample.rb</code> look some thing like this</p> <pre><code>&lt;p&gt;class Batch &lt; ActiveRecord::Base&lt;/p&gt; &lt;p&gt;has_many :samples&lt;/p&gt; &lt;p&gt;end&lt;/p&gt; &lt;p&gt;class Sample &lt; ActiveRecord::Base &lt;/p&gt; &lt;p&gt;belongs_to :batch&lt;/p&gt; &lt;p&gt;end&lt;/p&gt; </code></pre>
    singulars
    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.
 

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