Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4 from jmazzi/master

Add Rails 3.2.2 compatibility
  • Loading branch information...
commit c2f7b70a97ba42a8ad234ae3f3330f5fca1fbe7e 2 parents 38fe76e + 895bbd4
@jamesds authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/country-select.rb
View
10 lib/country-select.rb
@@ -20,13 +20,15 @@ def country_options_for_select(selected = nil, priority_countries = nil)
end
country_options += options_for_select(priority_countries, selected)
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
-
+
# prevents selected from being included twice in the HTML which causes
# some browsers to select the second selected option (not priority)
# which makes it harder to select an alternative priority country
selected = nil if priority_countries.include?(selected)
end
+ country_options = country_options.html_safe if country_options.respond_to?(:html_safe)
+
return country_options + options_for_select(COUNTRIES, selected)
end
@@ -34,7 +36,7 @@ def country_options_for_select(selected = nil, priority_countries = nil)
COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
"Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
"Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
- "Bermuda", "Bhutan", "Bolivia, Plurinational State of", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina",
+ "Bermuda", "Bhutan", "Bolivia, Plurinational State of", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina",
"Botswana", "Bouvet Island", "Brazil",
"British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
"Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
@@ -71,7 +73,7 @@ def country_options_for_select(selected = nil, priority_countries = nil)
"Venezuela, Bolivarian Republic of", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.",
"Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
end
-
+
class InstanceTag
def to_country_select_tag(priority_countries, options, html_options)
html_options = html_options.stringify_keys
@@ -85,7 +87,7 @@ def to_country_select_tag(priority_countries, options, html_options)
)
end
end
-
+
class FormBuilder
def country_select(method, priority_countries = nil, options = {}, html_options = {})
@template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
Please sign in to comment.
Something went wrong with that request. Please try again.