19

I have the following which creates a select box:

<%=select_tag "people", options_from_collection_for_select(@people, "id", "name")%>

This creates an item for each person, problem is I would like a "All People" value 0, option added and selected by default on load?

does the select_tag in rails 3 support this?

Thanks

AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

1 Answers1

23

Simply include a :include_blank => 'All People' option in your select_tag:

<%= select_tag "people", options_from_collection_for_select(@people, "id", "name"), :include_blank => 'All People' %>
vonconrad
  • 25,227
  • 7
  • 68
  • 69
  • 2
    The `:include_blank => "All people"` generates the following code: ``. Perhaps they've changed the syntax or something? – imjp Jul 16 '11 at 21:15
  • 10
    include_blank now takes a true/false value. To add a default option, :prompt => 'Select One' is the way to go. It also needs to go within the options hash. in all, `<%= select_tag "people", options_from_collection_for_select(@people, "id", "name"), { :prompt => 'All People' } %>` – Sunil Gowda Mar 28 '12 at 04:53