Collection_select - prepending a "any" option

Say I have a normal 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’”…?


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 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