title: mongoid save embedded documents
body: <p>I'm trying to build up on the following tutorial from railscast:
  <a href="http://railscasts.com/episodes/196-nested-model-form-part-1" rel="nofollow">http://railscasts.com/episodes/196-nested-model-form-part-1</a></p>
  
  <p>I'm trying to make everything work with mongodb and mongoid.</p>
  
  <p>the scenario is:
  I want to creates events linked to a location. Each events (dance class) contains many lessons.
  So I thought that an embedded relationship would be perfect.</p>
  
  <p>Here are my models</p>
  
  <h3>model Lesson</h3>
  
  <pre><code>class Lesson
    include Mongoid::Document
    include Mongoid::Slug
    field :name, :type =&gt; String
  
    embedded_in :event
  
    slug :name
  end
  </code></pre>
  
  <h3>model Event</h3>
  
  <pre><code>class Event
    include Mongoid::Document
    include Mongoid::Slug
    include Mongoid::Timestamps
    include Mongoid::MultiParameterAttributes
  
    field :name, :type =&gt; String
    field :description, :type =&gt; String
    field :date, :type =&gt; DateTime
  
    validates_presence_of :name
  
    has_one :venue
    referenced_in :venue
    embeds_many :lessons
  
    slug :name 
  end
  </code></pre>
  
  <h3>model Venue</h3>
  
  <pre><code>class Venue
    include Mongoid::Document
    include Mongoid::Slug
    include Mongoid::Timestamps
    include Mongoid::MultiParameterAttributes
  
  
    field :name, :type =&gt; String
    field :location, :type =&gt; String
  
    validates_presence_of :name, :location
  
    belongs_to :event
  
    slug :name
  end
  </code></pre>
  
  <h3>event controller</h3>
  
  <pre><code>def create
    @event = Event.new(params[:event])
      if @event.save
      flash[:notice] = 'Event was successfully created.'
    end
   respond_with(@Event, :location =&gt; events_url)
  end
  
  def update
    # @event = Event.find(params[:id])
     @event = Event.find_by_slug(params[:id])
     if @event.update_attributes(params[:event])
        flash[:notice] = "Event was succesfully updated"
      end
    respond_with(@event)
  end
  </code></pre>
  
  <p>Then I have my Event view where I can create events and link it to a Venue. But I'd like to be abe to create the lessons from the Event view/model.</p>
  
  <p>so I used the <code>fields_for</code> to generate a field linked to the Lessons model.</p>
  
  <pre><code>= form_for @event do |f|
    .field
      = f.label :name
      %br/
      = f.text_field :name
    .field
      = f.label :description
      %br/
      = f.text_area :description
    .field
      = f.label :venue_id
      %br/
      = f.collection_select :venue_id, Venue.all, :id, :name
    .field
      = f.label :date
      %br/
      = f.datetime_select :date
    %h3 Add a Class
      = f.fields_for :lessons do |builder|
       = render "lesson_fields", :f =&gt; builder
   .actions
      = f.submit 'Save'
  </code></pre>
  
  <p>When I create or edit a new event I get an error message:</p>
  
  <pre><code>undefined method `extract_id' for "test":String
  </code></pre>
  
  <p>But the request parameter message on the error page shows my lessons value in the Event document.</p>
  
  <pre><code>"lessons"=&gt;{"name"=&gt;"test name lesson"}
  </code></pre>
  
  <p>When I remove the fields_for line, everything works fine. But then i don't know how to save the value for the nested documents.</p>