Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Call html_safe when needed (>= Rails 3.2.2)

This commit caused it to break
rails/rails@621d219
  • Loading branch information...
commit 895bbd41c867a0fdce5e647834b6fb06e6fc1627 1 parent 38fe76e
Justin Mazzi jmazzi authored

Showing 1 changed file with 6 additions and 4 deletions. Show diff stats Hide diff stats

  1. +6 4 lib/country-select.rb
10 lib/country-select.rb
@@ -20,13 +20,15 @@ def country_options_for_select(selected = nil, priority_countries = nil)
20 20 end
21 21 country_options += options_for_select(priority_countries, selected)
22 22 country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
23   -
  23 +
24 24 # prevents selected from being included twice in the HTML which causes
25 25 # some browsers to select the second selected option (not priority)
26 26 # which makes it harder to select an alternative priority country
27 27 selected = nil if priority_countries.include?(selected)
28 28 end
29 29
  30 + country_options = country_options.html_safe if country_options.respond_to?(:html_safe)
  31 +
30 32 return country_options + options_for_select(COUNTRIES, selected)
31 33 end
32 34
@@ -34,7 +36,7 @@ def country_options_for_select(selected = nil, priority_countries = nil)
34 36 COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
35 37 "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
36 38 "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
37   - "Bermuda", "Bhutan", "Bolivia, Plurinational State of", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina",
  39 + "Bermuda", "Bhutan", "Bolivia, Plurinational State of", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina",
38 40 "Botswana", "Bouvet Island", "Brazil",
39 41 "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
40 42 "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)
71 73 "Venezuela, Bolivarian Republic of", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.",
72 74 "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
73 75 end
74   -
  76 +
75 77 class InstanceTag
76 78 def to_country_select_tag(priority_countries, options, html_options)
77 79 html_options = html_options.stringify_keys
@@ -85,7 +87,7 @@ def to_country_select_tag(priority_countries, options, html_options)
85 87 )
86 88 end
87 89 end
88   -
  90 +
89 91 class FormBuilder
90 92 def country_select(method, priority_countries = nil, options = {}, html_options = {})
91 93 @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)

0 comments on commit 895bbd4

Please sign in to comment.
Something went wrong with that request. Please try again.