lib/plugins/country_select/lib/country_select.rb
# 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.
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.

Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
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 . 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)
        country_options = ""
        if priority_countries.blank?
          priority_countries = ["United States", "Argentina", "Australia", "Brasil", "Canada", "Finland", "France", "Germany", "Italy", "Japan", "Mexico", "Norway", "Poland", "Portugal", "Spain", "Sweden", "Russia", "United Kingdom"]
        end
        priority_countries_iso = COUNTRIES.select{|c| priority_countries.include?(c[0]) }
        unless selected.nil?
            selected = COUNTRIES.select{|c| selected.include?(c[1]) }.flatten
        end
        country_options += options_for_select(priority_countries_iso, selected)
        country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
        other_countries = COUNTRIES.select{|c| !priority_countries.include?(c[0]) }
        return (country_options + options_for_select(other_countries, selected)).html_safe
      end
def country_options_for_select ( selected = nil , priority_countries = nil ) country_options = "" if priority_countries . blank? priority_countries = [ "United States" , "Argentina" , "Australia" , "Brasil" , "Canada" , "Finland" , "France" , "Germany" , "Italy" , "Japan" , "Mexico" , "Norway" , "Poland" , "Portugal" , "Spain" , "Sweden" , "Russia" , "United Kingdom" ] end priority_countries_iso = COUNTRIES . select { | c | priority_countries . include? ( c [ 0 ] ) } unless selected . nil? selected = COUNTRIES . select { | c | selected . include? ( c [ 1 ] ) } . flatten end country_options += options_for_select ( priority_countries_iso , selected ) country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" other_countries = COUNTRIES . select { | c | ! priority_countries . include? ( c [ 0 ] ) } return ( country_options + options_for_select ( other_countries , selected ) ) . html_safe end
Returns a string of option tags for pretty much any country in the world.
Returns a string of option tags for pretty much any country in the world .
# Add iso code for priority countries  # Add iso code for selected countries if not nil
selected
<not_specific>
priority_countries
<not_specific>