Module: ActionView::Helpers::FormOptionsHelper
- Defined in:
- lib/countries/select_helper.rb
Instance Method Summary collapse
- #country_options_for_select(selected = nil, priority_countries = nil) ⇒ Object
- #country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#country_options_for_select(selected = nil, priority_countries = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/countries/select_helper.rb', line 10 def (selected = nil, priority_countries = nil) = "" if priority_countries priority_countries = [*priority_countries].map {|x| [x,ISO3166::Country::NameIndex[x]] } += (priority_countries, selected) += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" # prevent 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?([ISO3166::Country[selected].name, selected]) end = .html_safe if .respond_to?(:html_safe) countries = ISO3166::Country::Names.map{|(name,alpha2)| [name.html_safe,alpha2] } return + (countries, selected) end |
#country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object
6 7 8 |
# File 'lib/countries/select_helper.rb', line 6 def country_select(object, method, priority_countries = nil, = {}, = {}) InstanceTag.new(object, method, self, .delete(:object)).to_country_select_tag(priority_countries, , ) end |