Forum: Ruby on Rails collection_select - adding an option for "all"

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fe49cddbc2de209390dfd1663e8bcee4?d=identicon&s=25 kathys39 (Guest)
on 2007-02-15 15:01
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
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-15 17:01
(Received via mailing list)
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 =>
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-15 17:09
(Received via mailing list)
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.
Fe49cddbc2de209390dfd1663e8bcee4?d=identicon&s=25 kathys (Guest)
on 2007-02-16 13:23
Works like a charm - thank you!
This topic is locked and can not be replied to.