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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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) On 2/15/07, kathys39 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On 2/15/07, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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) > > On 2/15/07, kathys39 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > 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 > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Works like a charm - thank you! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---