title: Ruby on rails - insert dynamic form drop down menu values to table
body: <p>I'm trying to insert a drop down menu values to a table named <strong>units</strong> and that drop values are coming from another model named <strong>properties</strong>.</p>
  
  <p>Here is the schema of the units.</p>
  
  <pre><code>create_table "units", :force =&gt; true do |t|
      t.string   "number"
      t.decimal  "monthly_rent"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.integer  "property_id"
    end
  </code></pre>
  
  <p>on my view/units/new.html.erb I have this.</p>
  
  <pre><code>&lt;% form_for @unit do |f| %&gt;
  &lt;%= f.error_messages %&gt;
  &lt;p&gt;
      &lt;%= f.label :property_id %&gt;
      &lt;br/&gt;
      &lt;%= select (:unit, :property_id, Property.all.collect  {|property| [property.name,property.id,]}) %&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;%= f.label :number %&gt;
      &lt;br/&gt;
      &lt;%= f.text_field :number %&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;%= f.label :monthly_rent %&gt;
      &lt;br/&gt;
      &lt;%= f.text_field :monthly_rent %&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;%= f.submit "Submit" %&gt;
  &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And here is my controller method</p>
  
  <pre><code>def create
      @unit = Unit.new(params[:unit])
   # @unit.property_id = 1
  
      if @unit.save
        flash[:notice] = "Successfully created unit."
        redirect_to @unit
      else
        render :action =&gt; 'new'
      end
    end
  </code></pre>
  
  <p>Only <code>number</code> and <code>monthy_rent</code> getting inserted to the table but the <code>property_id</code> doesn't come. Can some body help me on this please? Thanks </p>