title: Rails 3 date field is blank after form submit
body: <p>Rails newbie here.</p>
  
  <p>I have 2 models: Target and Observation</p>
  
  <p>Target works fine. I generated scaffolding for Observation, like this: </p>
  
  <pre><code>rails generate scaffold Observation date:date target:references
  </code></pre>
  
  <p>So app/models/observation.rb says:</p>
  
  <pre><code>class Observation &lt; ActiveRecord::Base
    belongs_to :target
  end
  </code></pre>
  
  <p>Then I edited app/models/target.rb:</p>
  
  <pre><code>class Target &lt; ActiveRecord::Base
    has_many :observations
  end
  </code></pre>
  
  <p>The scaffolding created app/views/observations/_form.html.erb which includes:</p>
  
  <pre><code>&lt;div class="field"&gt;
    &lt;%= f.label :target %&gt;&lt;br /&gt;
    &lt;%= f.text_field :target %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And app/controllers/observation_controller.rb which includes:</p>
  
  <pre><code>def create
    @observation = Observation.new(params[:observation])
  </code></pre>
  
  <p>I then go to create a new Observation. I enter a date and the ID of a target in the target field. When I submit, I get this error in the browser:</p>
  
  <pre><code>ActiveRecord::AssociationTypeMismatch in ObservationsController#create
  Target(#2190392620) expected, got String(#2148287480)
  </code></pre>
  
  <p>Seems like the scaffolding would set up something that would work. But the error makes sense. It's receiving the ID of the Target instead of the Target itself. So I edited app/controllers/observation_controller.rb to say:</p>
  
  <pre><code>def create
    @target = Target.find(params[:observation][:target])
    @observation = @target.observations.create(:date =&gt; params[:observation][:date])
  </code></pre>
  
  <p>Now it creates the Observation record, with the reference to the Target. But the date field is blank.</p>
  
  <p>I realize this may be a dumb newbie or RTFM question, but I'd really appreciate a pointer in the right direction. Thanks.</p>
  
  <hr>
  
  <p>Here's the full contents of the form, after changing it to reflect the answer received.</p>
  
  <pre><code>&lt;%= form_for(@observation) do |f| %&gt;
    &lt;% if @observation.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@observation.errors.count, "error") %&gt; prohibited this observation from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @observation.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :date %&gt;&lt;br /&gt;
      &lt;%= f.date_select :date %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :target %&gt;&lt;br /&gt;
      &lt;%= f.collection_select :target_id, Target.all, :id, :name %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>