title: Mongoid Create Embedded Document Inside Parent
body: <p>I have two models <strong>User</strong> and <strong>Status</strong>.
  Status is embedded in User:</p>
  
  <p><strong>User.rb</strong></p>
  
  <pre><code>class User
  
    include Mongoid::Document
    include Mongoid::Timestamps
  
    embeds_one :status, as: :statusable
  </code></pre>
  
  <p><strong>Status.rb</strong></p>
  
  <pre><code>class Status
  
    include Mongoid::Document
    include Mongoid::Timestamps
  
    embedded_in :statusable, polymorphic: true
  </code></pre>
  
  <p>Now I'm trying to create the status Document Inside user:</p>
  
  <pre><code>* User.create!(:name =&gt;'try',:status =&gt; {:num =&gt; '111'})
  =&gt; NameError: uninitialized constant Statu
      from /var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:230:in 'block in constantize'
      from /var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in 'each'
      ....
      ....
  
  * u = User.create!(:name =&gt;'try')
  u.status = Status.create!(:num =&gt; '222')
  =&gt; Mongoid::Errors::NoParent: 
  Problem:
    Cannot persist embedded document Status without a parent document.
  Summary:
    If the document is embedded, in order to be persisted it must always have a reference to its parent document. This is most likely caused by either calling Status.create or Status.create! without setting the parent document as an attribute.
  Resolution:
    Ensure that you have set the parent relation if instantiating the embedded document direcly, or always create new embedded documents via the parent relation.
  
  * u.status = {:num =&gt; '222'}
  =&gt; NameError: uninitialized constant Statu
  </code></pre>
  
  <p>Any idea why this happens?</p>