![](/img/trans.png)
[英]Rails: Using an object in an array as the object argument for collection_select
[英]Rails 3: add object using collection_select
我在_forms視圖中包含以下代碼。
<div class="field">
Shop: <%= f.collection_select :shop, @shop, :shopname, :shopname %><br />
</div>
但是,當我提交表單時,沒有對象添加到數據庫中。 但是,這可行:
<div class="field">
<%= f.label :shop %><br />
<%= f.text_field :shop %>
</div>
這是我手動添加ID的地方。 collection_select確實會檢索下拉列表中的所有商店名稱。
謝謝您的幫助!
如果商店確實是您的案例的參考,也許這樣會更好
<div class="field">
Shop: <%= f.collection_select :shop_id, @shops, :id, :shopname %><br />
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.