Shyam
Shyam

Reputation: 2377

Rails 3: add object using collection_select

I have the following code inside the _forms view.

<div class="field">
   Shop: <%= f.collection_select :shop, @shop, :shopname, :shopname %><br />
</div>

However, no object is added to the database when I submit the form. This however works:

 <div class="field">
    <%= f.label :shop %><br />
    <%= f.text_field :shop %>
  </div>

This where I am adding manually the id. The collection_select does retrieve all the shopnames in the dropdown list.

Thank you for your help!

Upvotes: 0

Views: 1068

Answers (1)

shingara
shingara

Reputation: 46914

Maybe like that is better if shop is really a reference in your case

<div class="field">
   Shop: <%= f.collection_select :shop_id, @shops, :id, :shopname %><br />
</div>

Upvotes: 1

Related Questions