开发者

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'} %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜