Anybody know how to add a Blank option to a select_tag. This is what I have now <%= select_tag "province","<option></option> <option>Prince Edward Island</option> <option>New Brunswick</option> <option>Nova Scotia</option> <option>Newfoundland</option>" %> This is the output I would like <select name="province"><option value="">All</option> <option value="Prince Edward Island">Prince Edward Island</option> <option value="New Brunswick">New Brunswick</ option> <option value="Nova Scotia">Nova Scotia</ option> <option value="Newfoundland">Newfoundland</ option></select> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Anybody know how to add a Blank option to a select_tag. This is what I > have nowadd as an option... :include_blank => true -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks but how do I add that into the code. I tried: <%= select_tag "province","<option ></option> <option>Prince Edward Island</option> <option>New Brunswick</option> <option>Nova Scotia</option> <option>Newfoundland</option> :include_blank => true" %> I am a newbie so please excuse me. On Apr 2, 12:19 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > Anybody know how to add a Blank option to a select_tag. This is what I > > have now > > add as an option... :include_blank => true > > -philip--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Sean, Why don''t you put those options in, then? Julian Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO (#2) OUT NOW! http://sensei.zenunit.com/ On 03/04/2008, at 1:23 AM, Shawn B wrote:> > Anybody know how to add a Blank option to a select_tag. This is what I > have now > > <%= select_tag "province","<option></option> > <option>Prince Edward Island</option> > <option>New Brunswick</option> > <option>Nova Scotia</option> > <option>Newfoundland</option>" > %> > > This is the output I would like > <select name="province"><option value="">All</option> > <option value="Prince Edward Island">Prince > Edward Island</option> > <option value="New Brunswick">New Brunswick</ > option> > <option value="Nova Scotia">Nova Scotia</ > option> > <option value="Newfoundland">Newfoundland</ > option></select> > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How about something like this: provinces = ["", "Prince Edward Island", "New Brunswick", "Nova Scotia", ...] province_collection = provinces.collect{|province| [province, province]} province_options = options_for_select(province_collection) <%= select_tag :province, province_options %> The first three lines could/should be in the controller (in which case province_options would need to be an instance variable @province_options). I''ve broken them down just for the sake of clarity; you could easily enough chain things together. The first line just creates an array of strings of province names and the second line creates a new array that will look like this [['''', ''''], [''PEI'', ''PEI''], ...] options_for_select (third line) takes that array and converts it into a string of option tags that is suitable for use with your select_tag. On Apr 2, 10:23 am, Shawn B <sba...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Anybody know how to add a Blank option to a select_tag. This is what I > have now > > <%= select_tag "province","<option></option> > <option>Prince Edward Island</option> > <option>New Brunswick</option> > <option>Nova Scotia</option> > <option>Newfoundland</option>" > %> > > This is the output I would like > <select name="province"><option value="">All</option> > <option value="Prince Edward Island">Prince > Edward Island</option> > <option value="New Brunswick">New Brunswick</ > option> > <option value="Nova Scotia">Nova Scotia</ > option> > <option value="Newfoundland">Newfoundland</ > option></select>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---