I am using Rails 3 and I am having a problem. My collection_select is not populating the field in the DB. This is what my view looks like: (some html was removed)
f.label "Company Name"
@c = Company.all
collection_select(:Company , :company_id, @c, :id , :companyName, {:prompt => true})
f.submit
The drop down list has the correct values, but when I submit it, this is what my params looks like: "Company"=>{"company_id"=>"2"}. I don’t have a field called company, but I do have a field called company_id and a table called company. Is my syntax correct?
Processing by RecordsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WLzwCoZFCUhyH9ZqYWYLmaQwyleB3JLoTnb4lhftKzc=", "record"=>{"title"=>"test", "Company"=>{"company_id"=>"2"}, "commit"=>"Create record"}
AREL (2.0ms) INSERT INTO "records" ("company_id", "title", "created_at", "updated_at") VALUES (NULL, 'test','2011-05-17 05:01:38.905717', '2011-05-17 05:01:38.905717')
Redirected to http://localhost:3000/Records/7
Completed 302 Found in 150ms
Try this
or