Ruby on Rails: how do I use a default placeholder thing in a select_tag?

后端 未结 3 1472
傲寒
傲寒 2020-12-14 00:18
 <%= select_tag(:services, 
                       options_from_collection_for_select(Service.all, :id, :name))%>

And it displays all the ser

3条回答
  •  悲哀的现实
    2020-12-14 01:02

    The better way to do this would be to use the :prompt parameter. Something like:

    select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {:prompt => 'Select Person'})
    

    http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html

提交回复
热议问题