Hi Veera,
I got the following from
http://railsmanual.com/module/ActionView::Helpers::FormOptionsHelper/country_select
but it seems to be down now. Pasted here for your convenience:
1. Install the tzinfo gem
# sudo gem install tzinfo
2. Install the tzinfo_timezone plugin
# ruby script/plugin install tzinfo_timezone
3. Add the following code to your application helper:
def make_attributes(hsh)
unless hsh.nil?
output = ""
hsh.each do |key, val|
output << " #{key}=\"#{val}\""
end
end
output
end
def country_code_select(object, method, priority_countries=nil,
options={}, html_options={})
countries = [TZInfo::Country.all.collect{|x|x.name},
TZInfo::Country.all_codes].transpose.sort
if priority_countries.nil?
output = select(object, method, countries, options,
html_options)
else
output = "<select id='#{object}_#{method}' name='#{object}
[#{method}]'#{make_attributes html_options}>\n"
if options[:include_blank] == true
output << "<option value=''></option>"
end
priority_countries.each do |pc|
if options[:selected] == pc[:code] or options[:selected] ==
pc[:name]
output << "<option value='#{pc[:code]}'
#{pc[:name]}</option>\n"
else
output << "<option value='#{pc[:code]}'>#{pc[:name]}</option>
\n"
end
end
output << "<option value='' disabled>----------------------------
</option>\n"
output << options_for_select(countries, options[:selected])
output << "</select>\n"
end
output
end
4. Use the helper like so in your views:
<%= country_code_select(:order, :ship_to_country,
priority_countries=[{:code=>'US',:name=>'United States'}],
{:selected=>'DK',:include_blank=>true},{:style=>'border:10px solid
red;'}) %>
Hope that helps,
Alan