Forum: Ruby on Rails collection_select - prepending a "any" option

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.
56eb877c42e47774db729bcfb8cad46f?d=identicon&s=25 sbeam (Guest)
on 2007-04-30 23:43
(Received via mailing list)
Say I have a normal <SELECT> tag being generated thusly:

    <%= collection_select :task, :id, Task.find(:all), :id, :name %>

what is the easiest way to add a "ANY" option to the top of the option
list? I know Task.find(:all) returns a collection object, so is there
a unshift() for that?

well OK I tried:

     Task.find(:all).unshift([:id=>0, :name=>'ANY'])

but that is just a vanilla Array with "undefined method `name'"....?

56eb877c42e47774db729bcfb8cad46f?d=identicon&s=25 sbeam (Guest)
on 2007-05-01 00:46
(Received via mailing list)
Found the answer in the source for actionpack-1.13.2/lib/action_view/

the :prompt option can take a value that goes atop ->

<%= collection_select :task, :id, Task.find(:all), :id, "type_name",
{ :prompt => '--- any ---' } %>
This topic is locked and can not be replied to.