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

后端 未结 3 1470
傲寒
傲寒 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 00:49

    <%= select_tag(:services, 
                   Service.all.collect { |c| [c.id, c.name] }.
                   insert(0, "Select a Service"))%>
    

    As answered for the question, this is for Rails 2.3. For Rails 3, see Prathan Thananart's answer.

提交回复
热议问题