Note that there are some explanatory texts on larger screens.

plurals
  1. PONested attributes not saving for references_one in Mongoid
    text
    copied!<p>I had this working fine yesterday, made some changes and I have no idea how I broke it. I'm sure it's a typo somewhere, but I cannot see it.</p> <p>Any changes made to the nested model in the form are just not being saved at all, the development log shows the attributes going through - and they appear to be in the right format, but it's just not updating at all.</p> <p>I have a <code>User</code> model which references_one <code>Biography</code> like so:</p> <pre><code># app/models/user.rb class User include Mongoid::Document include Mongoid::Timestamps field :first_name, :type =&gt; String field :last_name, :type =&gt; String devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable references_one :biography accepts_nested_attributes_for :biography #--snip--- end # app/models/biography.rb class Biography include Mongoid::Document include Mongoid::Timestamps field :content, :type =&gt; String field :role, :type =&gt; String field :is_crew, :type =&gt; Boolean referenced_in :user end </code></pre> <p>And finally my form (i'm using simple form here, but for the most part it behaves very similar to formtastic):</p> <pre><code>&lt;%= simple_form_for [:manage, @user], :html =&gt; {:multipart =&gt; true}, :position =&gt; :left do |f| %&gt; &lt;h2&gt;Login details&lt;/h2&gt; &lt;%= f.input :email, :input_html =&gt; {:class =&gt; "text"} %&gt; &lt;%= f.input :first_name, :input_html =&gt; {:class =&gt; "text"} %&gt; &lt;%= f.input :last_name, :input_html =&gt; {:class =&gt; "text"} %&gt; &lt;div class="biography"&gt; &lt;h2&gt;Biography&lt;/h2&gt; &lt;%= f.simple_fields_for :biography do |biography_form| %&gt; &lt;%= biography_form.input :role, :input_html =&gt; {:class =&gt; "text"} %&gt; &lt;%= biography_form.input :content, :as =&gt; :text, :input_html =&gt; {:class =&gt; "textarea"} %&gt; &lt;%= biography_form.input :is_crew, :as =&gt; :boolean %&gt; &lt;%- end -%&gt; &lt;/div&gt; &lt;%= f.submit "Save user", :class =&gt; "submit mid" %&gt; &lt;% end %&gt; </code></pre> <p>And some output from my development log, incase the answers lie there, and I just cant see them:</p> <pre><code> Started POST "/manage/users/john-doe" for 127.0.0.1 at Wed Dec 15 11:42:09 +1100 2010 Processing by Manage::UsersController#update as HTML Parameters: {"commit"=&gt;"Save user", "authenticity_token"=&gt;"44QlHsbKb8Pm91wnxWJa8Y0QsUXDzp/3rVpfs3G1Inc=", "utf8"=&gt;"✓", "id"=&gt;"john-doe", "user"=&gt;{"biography_attributes"=&gt;{"is_crew"=&gt;"0", "role"=&gt;"Tenor", "id"=&gt;"4d080de56a4f1dfe7700000e", "content"=&gt;"John was born on the 1st of January, 1970."}, "last_name"=&gt;"Doe", "first_name"=&gt;"Johnathan", "email"=&gt;"testing@involved.com.au"}} the_idea_of_north_development['users'].find({:_id=&gt;BSON::ObjectId('4d06e6036a4f1dcb1b000001')}, {}).limit(-1) the_idea_of_north_development['users'].find({:slug=&gt;"john-doe"}, {}).limit(-1) the_idea_of_north_development['biographies'].find({"user_id"=&gt;BSON::ObjectId('4d080de06a4f1dfe7700000d')}, {}).limit(-1) the_idea_of_north_development['$cmd'].find({"count"=&gt;"users", "query"=&gt;{:_id=&gt;{"$ne"=&gt;BSON::ObjectId('4d080de06a4f1dfe7700000d')}, :email=&gt;/^testing@involved\.com\.au$/i}, "fields"=&gt;nil}, {}).limit(-1) the_idea_of_north_development['users'].find({"slug"=&gt;"johnathan-doe"}, {}) MONGODB the_idea_of_north_development['users'].update({"_id"=&gt;BSON::ObjectId('4d080de06a4f1dfe7700000d')}, {"$set"=&gt;{"slug"=&gt;"johnathan-doe", "updated_at"=&gt;Wed Dec 15 00:42:09 UTC 2010, "first_name"=&gt;"Johnathan"}}) Redirected to http://lvh.me:3000/manage/users Completed 302 Found in 17ms </code></pre> <p>Any changes to the <code>User</code> model update fine, but changes to the <code>Biography</code> are unsaved. Help me hive-mind, you're my only hope!</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