Collection_select - adding an option for "all"

I’m using collection_select to populate a drop-down menu with items from
a database. That part is working fine. I’d like to add an option for
“all” in the drop-down menu in case the user wants to see data for all
the stores - how can I do this? Thanks

you can pass :include_blank => true as an option which adds a blank
option as the first option, but i don’t think there is a way to set
the text or value of the blank option.

collection_select(:model, :id, @models, “id”, “name”, :include_blank =>
true)

after looking at the source, there is a way…

use the :prompt => “All” option in place of the :include_blank option
and you will get an initial option with the text set to what you pass
and the value will be empty

collection_select(:model, :id, @models, “id”, “name”, :prompt => “All”)

then just check for a blank value being submitted.

Works like a charm - thank you!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs