title: Undefined method `__metadata' when I'm trying to update a User with embedded document using mongoid, devise in Rails 4
body: <p>I'm new in RoR, I'm trying to make a simple form where a user has two Positions in one company, so I'm using devise to manage the authentication and the creation of users. I just create a class Position to embed into the User and allow the admin select from a list of Positions which Position will have each user into the system. For now I can see the form, select the positions but when I try to save I get this error:</p>
  
  <blockquote>
    <p>undefined method `__metadata' for "54ed0c136c6f6337ff0a0000":String</p>
  </blockquote>
  
  <p>I saw the request and this is what the Controller receive:</p>
  
  <pre><code>Request
  
  Parameters:
  
  {"utf8"=&gt;"✓",
   "_method"=&gt;"put",
   "authenticity_token"=&gt;"auxoUaTmvkvRvLUUh3kUP0lzYo9aTotajjYVfy01OE0=",
   "user"=&gt;{"first_name"=&gt;"Fabian",
   "last_name"=&gt;"Jara",
   "email"=&gt;"admin@example.com",
   "age"=&gt;"35",
   "position_primary"=&gt;"54ed0c136c6f6337ff0a0000",
   "position_secundary"=&gt;"54ed0c136c6f6337ff0a0011"},
   "commit"=&gt;"Update"}
  </code></pre>
  
  <p>This is my User model:</p>
  
  <pre><code>class User
    include Mongoid::Document
    include Mongoid::Timestamps
    include User::AuthDefinitions
    include User::Roles
    include Mongoid::Paperclip
  
    has_many :identities
  
    embeds_one :position_primary, class_name: "Position"
    embeds_one :position_secundary, class_name: "Position"
  
    accepts_nested_attributes_for :position_primary, :position_secundary
  
    has_mongoid_attached_file :image
  
    validates_attachment_content_type :image, :content_type =&gt; ["image/jpg", "image/jpeg", "image/png", "image/gif"]
  
    field :first_name, type: String
    field :last_name, type: String
    field :roles_mask, type: Integer
    field :age, type: Integer
  
  end
  </code></pre>
  
  <p>and this is my Position model:</p>
  
  <pre><code>class Position
      include Mongoid::Document
  
      field :name, type: String
      field :status, type: Boolean
  
      embedded_in :users
  end
  </code></pre>
  
  <p>this is the view for edit the User information:</p>
  
  <pre><code>&lt;h2&gt;Edit &lt;%= resource_name.to_s.humanize %&gt;&lt;/h2&gt;
  &lt;%= simple_form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), :html =&gt; { :method =&gt; :put, :class =&gt; 'form-vertical' }) do |f| %&gt;
    &lt;%= f.input :first_name, :autofocus =&gt; true %&gt;
    &lt;%= f.input :last_name %&gt;
    &lt;%= f.input :email, :required =&gt; true %&gt;
    &lt;%= f.input :age %&gt;
    &lt;%= f.file_field :image %&gt; &lt;br&gt;
  
    &lt;%= f.select :position_primary, Position.all.collect {|p| [ p.name, p.id ] }, :prompt =&gt; "Select a position" %&gt;
    &lt;br&gt;
  
    &lt;%= f.select :position_secundary, Position.all.collect {|p| [ p.name, p.id ] }, :prompt =&gt; "Select a position" %&gt;
  &lt;br&gt;
    &lt;% if current_user.password_required? %&gt;
      &lt;%= f.input :password, :autocomplete =&gt; "off", :hint =&gt; "leave it blank if you don't want to change it", :required =&gt; false %&gt;
      &lt;%= f.input :password_confirmation, :required =&gt; false %&gt;
      &lt;%= f.input :current_password, :hint =&gt; "we need your current password to confirm your changes", :required =&gt; true %&gt;
    &lt;% end %&gt;
    &lt;%= f.button :submit, 'Update', :class =&gt; 'btn-primary' %&gt;
  &lt;% end %&gt;
  &lt;h3&gt;Cancel my account&lt;/h3&gt;
  &lt;p&gt;Unhappy? &lt;%= link_to "Cancel my account", registration_path(resource_name), :data =&gt; { :confirm =&gt; "Are you sure?" }, :method =&gt; :delete %&gt;.&lt;/p&gt;
  </code></pre>
  
  <p>and this is my RegistrationController:</p>
  
  <pre><code>class Users::RegistrationsController &lt; Devise::RegistrationsController
    before_filter :resource_params, if: :devise_controller?
  
    def resource_params
      devise_parameter_sanitizer.for(:sign_up) {|user| user.permit(:first_name, :last_name, :email, :password, :password_confirmation)}
      devise_parameter_sanitizer.for(:account_update) {|user| user.permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)}
    end
  
    def update
      authorize! :update, @user, :message =&gt; 'Not authorized as an administrator.'
      respond_to do |format|
  
        if @user.update_attributes(user_params)
          format.html { redirect_to @user, notice: 'User was successfully updated.' }
        else
          format.html { render action: 'edit' }
        end
      end
    end
  
    # Never trust parameters from the scary internet, only allow the white list through.
    def user_params
      params.require(:user).permit(:email, :first_name, :last_name, :image, :age, :position_primary, :position_secundary, :roles =&gt; [])
    end
  
    private :resource_params
  end
  </code></pre>
  
  <p>Thanks if you can give an idea of what could be wrong.</p>