Blank option with select tag

Anybody know how to add a Blank option to a select_tag. This is what I
have now

<%= select_tag “province”,"
Prince Edward Island
New Brunswick
Nova Scotia
Newfoundland"
%>

This is the output I would like
All
Prince
Edward Island
New Brunswick</
option>
Nova Scotia</
option>
Newfoundland</
option>

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

Thanks but how do I add that into the code. I tried:

<%= select_tag “province”,"
Prince Edward Island
New Brunswick
Nova Scotia
Newfoundland :include_blank
=> true" %>

I am a newbie so please excuse me.

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.

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/

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