Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/plugins/country_select/lib/country_select.rb

Constant Summary collapse

COUNTRIES =

All the countries included in the country_options output.

[
  ['Andorra', 'AN'],
  ['United Arab Emirates', 'AE'],
  ['Afghanistan', 'AF'],
  ['Antigua and Barbuda', 'AC'],
  ['Anguilla', 'AV'],
  ['Albania', 'AL'],
  ['Armenia', 'AM'],
  ['Netherlands Antilles', 'NT'],
  ['Angola', 'AO'],
  ['Antarctica', 'AY'],
  ['Argentina', 'AR'],
  ['American Samoa', 'AQ'],
  ['Austria', 'AU'],
  ['Australia', 'AS'],
  ['Aruba', 'AA'],
  ['Aland Islands', 'FI'],
  ['Azerbaijan', 'AJ'],
  ['Bosnia and Herzegovina', 'BK'],
  ['Barbados', 'BB'],
  ['Bangladesh', 'BG'],
  ['Belgium', 'BE'],
  ['Burkina Faso', 'UV'],
  ['Bulgaria', 'BU'],
  ['Bahrain', 'BA'],
  ['Burundi', 'BY'],
  ['Benin', 'BN'],
  ['Bermuda', 'BD'],
  ['Brunei', 'BX'],
  ['Bolivia', 'BL'],
  ['Brazil', 'BR'],
  ['Bahamas', 'BF'],
  ['Bhutan', 'BT'],
  ['Bouvet Island', 'BV'],
  ['Botswana', 'BC'],
  ['Belarus', 'BO'],
  ['Belize', 'BH'],
  ['Canada', 'CA'],
  ['Cocos (Keeling) Islands', 'CK'],
  ['Congo (Kinshasa)', 'CG'],
  ['Central African Republic', 'CT'],
  ['Congo (Brazzaville)', 'CF'],
  ['Switzerland', 'SZ'],
  ['Ivory Coast', 'IV'],
  ['Cook Islands', 'CW'],
  ['Chile', 'CI'],
  ['Cameroon', 'CM'],
  ['China', 'CH'],
  ['Colombia', 'CO'],
  ['Costa Rica', 'CS'],
  ['Serbia And Montenegro', 'YI'],
  ['Cuba', 'CU'],
  ['Cape Verde', 'CV'],
  ['Christmas Island', 'KT'],
  ['Cyprus', 'CY'],
  ['Czech Republic', 'EZ'],
  ['Germany', 'GM'],
  ['Djibouti', 'DJ'],
  ['Denmark', 'DA'],
  ['Dominica', 'DO'],
  ['Dominican Republic', 'DR'],
  ['Algeria', 'AG'],
  ['Ecuador', 'EC'],
  ['Estonia', 'EN'],
  ['Egypt', 'EG'],
  ['Western Sahara', 'WI'],
  ['Eritrea', 'ER'],
  ['Spain', 'SP'],
  ['Ethiopia', 'ET'],
  ['Finland', 'FI'],
  ['Fiji', 'FJ'],
  ['Falkland Islands', 'FK'],
  ['Micronesia', 'FM'],
  ['Faroe Islands', 'FO'],
  ['France', 'FR'],
  ['Gabon', 'GB'],
  ['United Kingdom', 'UK'],
  ['Grenada', 'GJ'],
  ['Georgia', 'GG'],
  ['French Guiana', 'FG'],
  ['Guernsey', 'GK'],
  ['Ghana', 'GH'],
  ['Gibraltar', 'GI'],
  ['Greenland', 'GL'],
  ['Gambia', 'GA'],
  ['Guinea', 'GV'],
  ['Guadeloupe', 'GP'],
  ['Equatorial Guinea', 'EK'],
  ['Greece', 'GR'],
  ['South Georgia and the South Sandwich Islands', 'SX'],
  ['Guatemala', 'GT'],
  ['Guam', 'GQ'],
  ['Guinea-Bissau', 'PU'],
  ['Guyana', 'GY'],
  ['Hong Kong S.A.R., China', 'HK'],
  ['Heard Island and McDonald Islands', 'HM'],
  ['Honduras', 'HO'],
  ['Croatia', 'HR'],
  ['Haiti', 'HA'],
  ['Hungary', 'HU'],
  ['Indonesia', 'ID'],
  ['Ireland', 'EI'],
  ['Israel', 'IS'],
  ['Isle of Man', 'IM'],
  ['India', 'IN'],
  ['British Indian Ocean Territory', 'IO'],
  ['Iraq', 'IZ'],
  ['Iran', 'IR'],
  ['Iceland', 'IC'],
  ['Italy', 'IT'],
  ['Jersey', 'JE'],
  ['Jamaica', 'JM'],
  ['Jordan', 'JO'],
  ['Japan', 'JA'],
  ['Kenya', 'KE'],
  ['Kyrgyzstan', 'KG'],
  ['Cambodia', 'CB'],
  ['Kiribati', 'KR'],
  ['Comoros', 'CN'],
  ['Saint Kitts and Nevis', 'SC'],
  ['North Korea', 'KN'],
  ['South Korea', 'KS'],
  ['Kuwait', 'KU'],
  ['Cayman Islands', 'CJ'],
  ['Kazakhstan', 'KZ'],
  ['Laos', 'LA'],
  ['Lebanon', 'LE'],
  ['Saint Lucia', 'ST'],
  ['Liechtenstein', 'LS'],
  ['Sri Lanka', 'CE'],
  ['Liberia', 'LI'],
  ['Lesotho', 'LT'],
  ['Lithuania', 'LH'],
  ['Luxembourg', 'LU'],
  ['Latvia', 'LG'],
  ['Libya', 'LY'],
  ['Morocco', 'MO'],
  ['Monaco', 'MN'],
  ['Moldova', 'MD'],
  ['Montenegro', 'MJ'],
  ['Madagascar', 'MA'],
  ['Marshall Islands', 'RM'],
  ['Macedonia', 'MK'],
  ['Mali', 'ML'],
  ['Myanmar', 'BM'],
  ['Mongolia', 'MG'],
  ['Macao S.A.R., China', 'MC'],
  ['Northern Mariana Islands', 'CQ'],
  ['Martinique', 'MB'],
  ['Mauritania', 'MR'],
  ['Montserrat', 'MH'],
  ['Malta', 'MT'],
  ['Mauritius', 'MP'],
  ['Maldives', 'MV'],
  ['Malawi', 'MI'],
  ['Mexico', 'MX'],
  ['Malaysia', 'MY'],
  ['Mozambique', 'MZ'],
  ['Namibia', 'WA'],
  ['New Caledonia', 'NC'],
  ['Niger', 'NG'],
  ['Norfolk Island', 'NF'],
  ['Nigeria', 'NI'],
  ['Nicaragua', 'NU'],
  ['Netherlands', 'NL'],
  ['Norway', 'NO'],
  ['Nepal', 'NP'],
  ['Nauru', 'NR'],
  ['Niue', 'NE'],
  ['New Zealand', 'NZ'],
  ['Oman', 'MU'],
  ['Panama', 'PM'],
  ['Peru', 'PE'],
  ['French Polynesia', 'FP'],
  ['Papua New Guinea', 'PP'],
  ['Philippines', 'RP'],
  ['Pakistan', 'PK'],
  ['Poland', 'PL'],
  ['Saint Pierre and Miquelon', 'SB'],
  ['Pitcairn', 'PC'],
  ['Puerto Rico', 'RQ'],
  ['Palestinian Territory', 'WE'],
  ['Portugal', 'PO'],
  ['Palau', 'PS'],
  ['Paraguay', 'PA'],
  ['Qatar', 'QA'],
  ['Reunion', 'RE'],
  ['Romania', 'RO'],
  ['Serbia', 'RB'],
  ['Russia', 'RS'],
  ['Rwanda', 'RW'],
  ['Saudi Arabia', 'SA'],
  ['Solomon Islands', 'BP'],
  ['Seychelles', 'SE'],
  ['Sudan', 'SU'],
  ['Sweden', 'SW'],
  ['Singapore', 'SN'],
  ['Saint Helena', 'SH'],
  ['Slovenia', 'SI'],
  ['Svalbard and Jan Mayen', 'SV'],
  ['Slovakia', 'LO'],
  ['Sierra Leone', 'SL'],
  ['San Marino', 'SM'],
  ['Senegal', 'SG'],
  ['Somalia', 'SO'],
  ['Suriname', 'NS'],
  ['Sao Tome and Principe', 'TP'],
  ['El Salvador', 'ES'],
  ['Syria', 'SY'],
  ['Swaziland', 'WZ'],
  ['Turks and Caicos Islands', 'TK'],
  ['Chad', 'CD'],
  ['French Southern Territories', 'FS'],
  ['Togo', 'TO'],
  ['Thailand', 'TH'],
  ['Tajikistan', 'TI'],
  ['Tokelau', 'TL'],
  ['East Timor', 'TT'],
  ['Turkmenistan', 'TX'],
  ['Tunisia', 'TS'],
  ['Tonga', 'TN'],
  ['Turkey', 'TU'],
  ['Trinidad and Tobago', 'TD'],
  ['Tuvalu', 'TV'],
  ['Taiwan', 'TW'],
  ['Tanzania', 'TZ'],
  ['Ukraine', 'UP'],
  ['Uganda', 'UG'],
  ['United States', 'US'],
  ['Uruguay', 'UY'],
  ['Uzbekistan', 'UZ'],
  ['Vatican', 'VT'],
  ['Saint Vincent and the Grenadines', 'VC'],
  ['Venezuela', 'VE'],
  ['British Virgin Islands', 'VI'],
  ['U.S. Virgin Islands', 'VQ'],
  ['Vietnam', 'VM'],
  ['Vanuatu', 'NH'],
  ['Wallis and Futuna', 'WF'],
  ['Samoa', 'WS'],
  ['Yemen', 'YM'],
  ['Mayotte', 'MF'],
  ['South Africa', 'SF'],
  ['Zambia', 'ZA'],
  ['Zimbabwe', 'ZI']
].sort
COUNTRIES_HASH =
{
  :AN => 'Andorra',
  :AE => 'United Arab Emirates',
  :AF => 'Afghanistan',
  :AC => 'Antigua and Barbuda',
  :AV => 'Anguilla',
  :AL => 'Albania',
  :AM => 'Armenia',
  :NT => 'Netherlands Antilles',
  :AO => 'Angola',
  :AY => 'Antarctica',
  :AR => 'Argentina',
  :AQ => 'American Samoa',
  :AU => 'Austria',
  :AS => 'Australia',
  :AA => 'Aruba',
  :FI => 'Aland Islands',
  :AJ => 'Azerbaijan',
  :BK => 'Bosnia and Herzegovina',
  :BB => 'Barbados',
  :BG => 'Bangladesh',
  :BE => 'Belgium',
  :UV => 'Burkina Faso',
  :BU => 'Bulgaria',
  :BA => 'Bahrain',
  :BY => 'Burundi',
  :BN => 'Benin',
  :BD => 'Bermuda',
  :BX => 'Brunei',
  :BL => 'Bolivia',
  :BR => 'Brazil',
  :BF => 'Bahamas',
  :BT => 'Bhutan',
  :BV => 'Bouvet Island',
  :BC => 'Botswana',
  :BO => 'Belarus',
  :BH => 'Belize',
  :CA => 'Canada',
  :CK => 'Cocos (Keeling) Islands',
  :CG => 'Congo (Kinshasa)',
  :CT => 'Central African Republic',
  :CF => 'Congo (Brazzaville)',
  :SZ => 'Switzerland',
  :IV => 'Ivory Coast',
  :CW => 'Cook Islands',
  :CI => 'Chile',
  :CM => 'Cameroon',
  :CH => 'China',
  :CO => 'Colombia',
  :CS => 'Costa Rica',
  :YI => 'Serbia And Montenegro',
  :CU => 'Cuba',
  :CV => 'Cape Verde',
  :KT => 'Christmas Island',
  :CY => 'Cyprus',
  :EZ => 'Czech Republic',
  :GM => 'Germany',
  :DJ => 'Djibouti',
  :DA => 'Denmark',
  :DO => 'Dominica',
  :DR => 'Dominican Republic',
  :AG => 'Algeria',
  :EC => 'Ecuador',
  :EN => 'Estonia',
  :EG => 'Egypt',
  :WI => 'Western Sahara',
  :ER => 'Eritrea',
  :SP => 'Spain',
  :ET => 'Ethiopia',
  :FI => 'Finland',
  :FJ => 'Fiji',
  :FK => 'Falkland Islands',
  :FM => 'Micronesia',
  :FO => 'Faroe Islands',
  :FR => 'France',
  :GB => 'Gabon',
  :UK => 'United Kingdom',
  :GJ => 'Grenada',
  :GG => 'Georgia',
  :FG => 'French Guiana',
  :GK => 'Guernsey',
  :GH => 'Ghana',
  :GI => 'Gibraltar',
  :GL => 'Greenland',
  :GA => 'Gambia',
  :GV => 'Guinea',
  :GP => 'Guadeloupe',
  :EK => 'Equatorial Guinea',
  :GR => 'Greece',
  :SX => 'South Georgia and the South Sandwich Islands',
  :GT => 'Guatemala',
  :GQ => 'Guam',
  :PU => 'Guinea-Bissau',
  :GY => 'Guyana',
  :HK => 'Hong Kong S.A.R., China',
  :HM => 'Heard Island and McDonald Islands',
  :HO => 'Honduras',
  :HR => 'Croatia',
  :HA => 'Haiti',
  :HU => 'Hungary',
  :ID => 'Indonesia',
  :EI => 'Ireland',
  :IS => 'Israel',
  :IM => 'Isle of Man',
  :IN => 'India',
  :IO => 'British Indian Ocean Territory',
  :IZ => 'Iraq',
  :IR => 'Iran',
  :IC => 'Iceland',
  :IT => 'Italy',
  :JE => 'Jersey',
  :JM => 'Jamaica',
  :JO => 'Jordan',
  :JA => 'Japan',
  :KE => 'Kenya',
  :KG => 'Kyrgyzstan',
  :CB => 'Cambodia',
  :KR => 'Kiribati',
  :CN => 'Comoros',
  :SC => 'Saint Kitts and Nevis',
  :KN => 'North Korea',
  :KS => 'South Korea',
  :KU => 'Kuwait',
  :CJ => 'Cayman Islands',
  :KZ => 'Kazakhstan',
  :LA => 'Laos',
  :LE => 'Lebanon',
  :ST => 'Saint Lucia',
  :LS => 'Liechtenstein',
  :CE => 'Sri Lanka',
  :LI => 'Liberia',
  :LT => 'Lesotho',
  :LH => 'Lithuania',
  :LU => 'Luxembourg',
  :LG => 'Latvia',
  :LY => 'Libya',
  :MO => 'Morocco',
  :MN => 'Monaco',
  :MD => 'Moldova',
  :MJ => 'Montenegro',
  :MA => 'Madagascar',
  :RM => 'Marshall Islands',
  :MK => 'Macedonia',
  :ML => 'Mali',
  :BM => 'Myanmar',
  :MG => 'Mongolia',
  :MC => 'Macao S.A.R., China',
  :CQ => 'Northern Mariana Islands',
  :MB => 'Martinique',
  :MR => 'Mauritania',
  :MH => 'Montserrat',
  :MT => 'Malta',
  :MP => 'Mauritius',
  :MV => 'Maldives',
  :MI => 'Malawi',
  :MX => 'Mexico',
  :MY => 'Malaysia',
  :MZ => 'Mozambique',
  :WA => 'Namibia',
  :NC => 'New Caledonia',
  :NG => 'Niger',
  :NF => 'Norfolk Island',
  :NI => 'Nigeria',
  :NU => 'Nicaragua',
  :NL => 'Netherlands',
  :NO => 'Norway',
  :NP => 'Nepal',
  :NR => 'Nauru',
  :NE => 'Niue',
  :NZ => 'New Zealand',
  :MU => 'Oman',
  :PM => 'Panama',
  :PE => 'Peru',
  :FP => 'French Polynesia',
  :PP => 'Papua New Guinea',
  :RP => 'Philippines',
  :PK => 'Pakistan',
  :PL => 'Poland',
  :SB => 'Saint Pierre and Miquelon',
  :PC => 'Pitcairn',
  :RQ => 'Puerto Rico',
  :WE => 'Palestinian Territory',
  :PO => 'Portugal',
  :PS => 'Palau',
  :PA => 'Paraguay',
  :QA => 'Qatar',
  :RE => 'Reunion',
  :RO => 'Romania',
  :RB => 'Serbia',
  :RS => 'Russia',
  :RW => 'Rwanda',
  :SA => 'Saudi Arabia',
  :BP => 'Solomon Islands',
  :SE => 'Seychelles',
  :SU => 'Sudan',
  :SW => 'Sweden',
  :SN => 'Singapore',
  :SH => 'Saint Helena',
  :SI => 'Slovenia',
  :SV => 'Svalbard and Jan Mayen',
  :LO => 'Slovakia',
  :SL => 'Sierra Leone',
  :SM => 'San Marino',
  :SG => 'Senegal',
  :SO => 'Somalia',
  :NS => 'Suriname',
  :TP => 'Sao Tome and Principe',
  :ES => 'El Salvador',
  :SY => 'Syria',
  :WZ => 'Swaziland',
  :TK => 'Turks and Caicos Islands',
  :CD => 'Chad',
  :FS => 'French Southern Territories',
  :TO => 'Togo',
  :TH => 'Thailand',
  :TI => 'Tajikistan',
  :TL => 'Tokelau',
  :TT => 'East Timor',
  :TX => 'Turkmenistan',
  :TS => 'Tunisia',
  :TN => 'Tonga',
  :TU => 'Turkey',
  :TD => 'Trinidad and Tobago',
  :TV => 'Tuvalu',
  :TW => 'Taiwan',
  :TZ => 'Tanzania',
  :UP => 'Ukraine',
  :UG => 'Uganda',
  :US => 'United States',
  :UY => 'Uruguay',
  :UZ => 'Uzbekistan',
  :VT => 'Vatican',
  :VC => 'Saint Vincent and the Grenadines',
  :VE => 'Venezuela',
  :VI => 'British Virgin Islands',
  :VQ => 'U.S. Virgin Islands',
  :VM => 'Vietnam',
  :NH => 'Vanuatu',
  :WF => 'Wallis and Futuna',
  :WS => 'Samoa',
  :YM => 'Yemen',
  :MF => 'Mayotte',
  :SF => 'South Africa',
  :ZA => 'Zambia',
  :ZI => 'Zimbabwe',
  :WW => 'Worldwide'
}

Instance Method Summary collapse

Instance Method Details

#country_options_for_select(selected = nil, priority_countries = nil) ⇒ Object

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.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/plugins/country_select/lib/country_select.rb', line 14

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

  country_options += options_for_select(priority_countries, 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

#country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object

Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.



6
7
8
# File 'lib/plugins/country_select/lib/country_select.rb', line 6

def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
  InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
end