how to add a new value to a dropdown list in Rails
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'} %>
精彩评论