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!
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.