module ActiveScaffold::Bridges class CountryHelper module CountryHelpers def country_select_class # TODO remove when rails 3.2 support is dropped defined?(ActionView::Helpers::InstanceTag) ? ActionView::Helpers::InstanceTag : ActionView::Helpers::Tags::CountrySelect end def country_select_options(options) # TODO remove when rails 3.2 support is dropped defined?(ActionView::Helpers::InstanceTag) ? options[:object] : options end # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. def country_select(object, method, priority_countries = nil, options = {}, html_options = {}) country_select_class.new(object, method, self, country_select_options(options)).to_country_select_tag(priority_countries, options, html_options) end def usa_state_select(object, method, priority_states = nil, options = {}, html_options = {}) country_select_class.new(object, method, self, country_select_options(options)).to_usa_state_select_tag(priority_states, options, html_options) end end module CountryOptionsHelpers # 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. 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 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