module ActiveScaffold::Bridges::CountryHelper::CountryOptionsHelpers
Constants
- COUNTRIES
All the countries included in the country_options output.
- USASTATES
Public Instance Methods
Returns a string of option tags for pretty much any country in the world. Supply a country name as selected
to have it marked as the selected option tag. You can also supply an array of countries as priority_countries
, so that they will be listed above the rest of the (long) list.
NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
# File lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb, line 24 def country_options_for_select(selected = nil, priority_countries = nil) if priority_countries country_options = options_for_select(priority_countries.collect {|country| [I18n.t("countries.#{country}", :default => country.to_s.titleize), country.to_s]} + [['-------------', '']], :selected => selected, :disabled => '') else country_options = options_for_select([]) end return country_options + options_for_select(COUNTRIES.collect {|country| [I18n.t("countries.#{country}", :default => country.to_s.titleize), country.to_s]}, :selected => selected) end
Returns a string of option tags for the states in the United States. Supply a state name as +selected to have it marked as the selected option tag. Included also is the option to set a couple of priority_states
in case you want to highligh a local area NOTE: Only the option tags are returned from this method, wrap it in a <select>
# File lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb, line 38 def usa_state_options_for_select(selected = nil, priority_states = nil) if priority_states state_options = options_for_select(priority_states + [['-------------', '']], :selected => selected, :disabled => '') else state_options = options_for_select([]) end if priority_states && priority_states.include?(selected) state_options += options_for_select(USASTATES - priority_states, :selected => selected) else state_options += options_for_select(USASTATES, :selected => selected) end return state_options end