簡體   English   中英

Rails 3:使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM