Note that there are some explanatory texts on larger screens.

plurals
  1. PONested attributes problem in rails 3 with mongoid (nested objects aren`t saved)
    primarykey
    data
    text
    <p>So I have a simple application as in <a href="http://railscasts.com/episodes/196-nested-model-form-part-1" rel="nofollow">RailsCast about nested forms.</a> and a problem is that when I submit the form (with survey and questions) <strong>the questions are not saved</strong>. </p> <p>My models (Survey, that has many Questions):</p> <pre><code>class Survey include Mongoid::Document field :name has_many :questions, :dependent =&gt; :destroy accepts_nested_attributes_for :questions, :allow_destroy =&gt; true end class Question include Mongoid::Document field :content belongs_to :survey end </code></pre> <p>and Survey Controller:</p> <pre><code>def new @survey = Survey.new 3.times {@survey.questions.build} .... </code></pre> <p>and a view:</p> <pre><code>&lt;%= form_for(@survey) do |f| %&gt; &lt;%= f.fields_for :questions do |builder| %&gt; &lt;%= builder.label :content, "Question" %&gt;&lt;br /&gt; &lt;%= builder.text_area :content, :rows =&gt; 3 %&gt;&lt;br /&gt; &lt;%= builder.check_box :_destroy %&gt; &lt;%= builder.label :_destroy, "Remove Question" %&gt; &lt;% end %&gt; ... </code></pre> <p>In my log I have:</p> <pre><code> Started POST "/surveys" for 127.0.0.1 at 2011-05-24 13:26:51 +0400 Processing by SurveysController#create as HTML Parameters: {"utf8"=&gt;"G£ô", "authenticity_token"=&gt;"tX0FfMiLbh1BwjuY4CuvAKt2UpTraY3vmdo58ocBnos=", "survey"=&gt;{"name"=&gt;" Rails", "questions_attributes"=&gt;{"0"=&gt;{"content"=&gt;"Are you fond of Rails?", "_destroy"=&gt;"0"}, "1"=&gt;{"content"=&gt;"Rails is the best, ha?", "_destroy"=&gt;"0"}, "2"=&gt;{"content"=&gt;"How many railscasts have you watched?", "_destroy"=&gt;"0"}}}, "commit "=&gt;"Create Survey"} MONGODB nested_attributes_development['surveys'].insert([{"name"=&gt;"Rails", "_id"=&gt;BSON::ObjectId('4ddb79dba5372914380000 69')}]) Redirected to http://localhost:3000/surveys/4ddb79dba537291438000069 </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.
 

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