0
我有一個下拉列表,我嘗試用ActiveRecord的結果填充。我想我不明白如何訪問我檢索的值,因爲下面的代碼填充我的下拉列表中的值,如使用ActiveRecord中的值填充下拉列表
#<Product:0x007f1f488565b0>
這顯然不是我想要的。
<%= f.select :accessory, options_for_select(Product.select(:item_number, :id).where(:accessory=> 't') {|c| [ c.item_number, c.id ] }), {include_blank: true}, { :class => 'form-control'} %>
如何使用項目編號和ID填充下拉列表?這個查詢中沒有涉及任何關係。我只想要一個附件標有「t」的產品清單。
謝謝馬克! 'Product.select(:item_number,:id).where(:accessory =>'t')。map {| c | [c.item_number,c.id]}'工作。 – mack