Hello, I'm trying to insert a drop down menu values to a table named units and that drop values are coming from another model named properties.
Here is the schema of the units.
create_table "units", :force => true do |t|
t.string "number"
t.decimal "monthly_rent"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "property_id"
end
on my view/units/new.html.erb I have this.
<% form_for @unit do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :property_id %>
<br/>
<%= select (:unit, :property_id, Property.all.collect {|property| [property.name,property.id,]}) %>
</p>
<p>
<%= f.label :number %>
<br/>
<%= f.text_field :number %>
</p>
<p>
<%= f.label :monthly_rent %>
<br/>
<%= f.text_field :monthly_rent %>
</p>
<p>
<%= f.submit "Submit" %>
</p>
<% end %>
And here is my controller method
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 => 'new'
end
end
Only number
and monthy_rent
getting inserted to the table but the property_id
doesn't come. Can some body help me on this please? Thanks