countries 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/countries/select_helper.rb +9 -8
- data/lib/countries/version.rb +1 -1
- metadata +2 -2
@@ -7,25 +7,26 @@ module ActionView
|
|
7
7
|
InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
|
8
8
|
end
|
9
9
|
|
10
|
-
def country_options_for_select(
|
10
|
+
def country_options_for_select(selected_country_code = nil, priority_countries = nil)
|
11
11
|
country_options = ""
|
12
12
|
|
13
13
|
if priority_countries
|
14
|
-
priority_countries = [*priority_countries].map {|x| [x,ISO3166::Country::NameIndex[x]] }
|
15
|
-
country_options += options_for_select(priority_countries,
|
14
|
+
priority_countries = [*priority_countries].map { |x| [x,ISO3166::Country::NameIndex[x]] }
|
15
|
+
country_options += options_for_select(priority_countries, selected_country_code)
|
16
16
|
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
17
17
|
|
18
|
-
# prevent
|
18
|
+
# prevent selected_country_code from being included twice in the HTML which causes
|
19
19
|
# some browsers to select the second selected option (not priority)
|
20
20
|
# which makes it harder to select an alternative priority country
|
21
|
-
|
21
|
+
if selected_country = ISO3166::Country[selected_country_code]
|
22
|
+
selected_country_code = nil if priority_countries.include?([selected_country.name, selected_country_code])
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
country_options = country_options.html_safe if country_options.respond_to?(:html_safe)
|
27
|
+
countries = ISO3166::Country::Names.map{ |(name,alpha2)| [name.html_safe,alpha2] }
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
return country_options + options_for_select(countries, selected)
|
29
|
+
country_options + options_for_select(countries, selected_country_code)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
data/lib/countries/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: countries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-02
|
13
|
+
date: 2013-03-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: currencies
|