Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>if I understand your requirements correctly, you're searching for nested forms as excellently described by Ryan Bates at railscasts.com</p> <p>Tutorial 1: <a href="http://railscasts.com/episodes/196-nested-model-form-part-1" rel="nofollow">Nested Model Form Part 1</a></p> <p>Tutorial 2: <a href="http://railscasts.com/episodes/197-nested-model-form-part-2" rel="nofollow">Nested Model Form Part 2</a></p> <p>Here is some more help for you:</p> <p>In your Bash model</p> <pre><code>has_many :samples accepts_nested_attributes_for :samples </code></pre> <p>Your Bash Controller will have at least 2 actions: new and create In your new action:</p> <pre><code>@bash = Bash.build 4.times { @bash.samples.build } # where 4 is the no. of samples, could also be param[:amount] in case you add a preliminary action with a form and an amount field, but I suggest using javascript as described in Tutorial 2 above for better user experience </code></pre> <p>In the create action:</p> <pre><code>@bash = Bash.new(params[:bash]) # you now have access to @bash.samples if @bash.save ... </code></pre> <p>And finally the "new" view:</p> <pre><code>&lt;%= form_for @bash do |f| %&gt; &lt;%= f.text_field :group_leader %&gt; &lt;!-- ... --&gt; &lt;%= f.fields_for :samples do |builder| %&gt; &lt;%= builder.text_field :sample_name %&gt; &lt;!-- ... --&gt; &lt;% end %&gt; &lt;%= end %&gt; </code></pre> <p>With this and the tutorials you should now be able to build a killer app for your degree's application. Good luck!</p>
 

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