开发者

how to add a new value to a dropdown list in Rails

开发者 https://www.devze.com 2022-12-26 05:13 出处:网络
In my item table, I have a itemname column which is currently a dropdown list taking values from DB. <%= select \'item\',\'itemname\',

In my item table, I have a itemname column which is currently a dropdown list taking values from DB.

<%= select 'item','itemname',
   Item.find(:all).collect{|c| [c.itemname]},{:include_blank => 'Select Name'} %>

How can I add a new value开发者_如何转开发 to this dropdown list through the application. Is there a provision to directly add value to the list?

Thanks


Do the following:

<%= select 'item','itemname',
   Item.all.map{|c| [c.itemname]}.concat(["Foo Item", "Bar Item"]),
   {:include_blank => 'Select Name'} %>
0

精彩评论

暂无评论...
验证码 换一张
取 消