Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating forms for Multiple Nested Resources in Rails 3
    primarykey
    data
    text
    <p>I have been following Ryan Bates' tutorial on nested forms <a href="http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast" rel="nofollow">Railscast 196</a></p> <p>The form for the new action shows the nested attributes for quizzes but does not show nested attributes for the key. I am guessing this is because quizzes have a has_many relationship where key has a has_one relationship... But I cannot figure out what I'm doing wrong?</p> <p>Any help is much appreciated!</p> <p>This is my model:</p> <pre><code>class Repository &lt; ActiveRecord::Base has_many :quizzes, :dependent =&gt; :destroy has_one :key, :dependent =&gt; :destroy accepts_nested_attributes_for :key, :quizzes end </code></pre> <p>This is my controller:</p> <pre><code>def new @repository = Repository.new 3.times { @repository.quizzes.build } @repository.key = Key.new respond_to do |format| format.html # new.html.erb format.xml { render :xml =&gt; @repository } end end </code></pre> <p>This is my view:</p> <pre><code>&lt;div class="field"&gt; &lt;%= f.label :wp_uid %&gt;&lt;br /&gt; &lt;%= f.text_field :wp_uid %&gt; &lt;% f.fields_for :quizzes do |quiz_fields| %&gt; &lt;p&gt; &lt;%= quiz_fields.label :name, "Name" %&gt;&lt;br /&gt; &lt;%= quiz_fields.text_field :name %&gt; &lt;/p&gt; &lt;% end %&gt; &lt;% f.fields_for :key do |key_fields| %&gt; &lt;div class="field"&gt; &lt;%= key_fields.label :value, "Value" %&gt;&lt;br /&gt; &lt;%= key_fields.text_field :value %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= key_fields.label :expiry, "Expiry" %&gt;&lt;br /&gt; &lt;%= key_fields.date_select :expiry %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre>
    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.
    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