Module: ActionView::Helpers::FormOptionsHelper
- Defined in:
- lib/iso/countries/form_helpers.rb
Instance Method Summary collapse
-
#iso_country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using iso_options_for_select to generate the list of option tags.
-
#iso_options_for_select(selected = nil, priority_countries = nil) ⇒ Object
Returns a string of option tags for pretty much any country in the world.
-
#to_iso_select_tag(priority_countries, options, html_options) ⇒ Object
:nodoc:.
Instance Method Details
#iso_country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using iso_options_for_select to generate the list of option tags.
6 7 8 |
# File 'lib/iso/countries/form_helpers.rb', line 6 def iso_country_select(object, method, priority_countries = nil, = {}, = {}) InstanceTag.new(object, method, self).to_iso_select_tag(priority_countries, , ) end |
#iso_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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/iso/countries/form_helpers.rb', line 15 def (selected = nil, priority_countries = nil) countries_for_select = {} ISO::Countries::COUNTRIES.each_pair {|code,name| countries_for_select[ISO::Countries.get_country(code)] = code.to_s } = "" if priority_countries priority_hash = {} priority_countries.each {|code| priority_hash[ISO::Countries.get_country(code)] = code.to_s } += (priority_hash.sort, selected) += "<option value=\"\">-------------</option>\n" end if priority_countries && priority_countries.include?(selected) += (countries_for_select.sort - priority_countries, selected) else += (countries_for_select.sort, selected) end return end |
#to_iso_select_tag(priority_countries, options, html_options) ⇒ Object
:nodoc:
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/iso/countries/form_helpers.rb', line 37 def to_iso_select_tag(priority_countries, , ) #:nodoc: if .has_key?(:class) [:class] = [:class] + " country" else [:class] = "country" end = .stringify_keys add_default_name_and_id() value = value(object) content_tag("select", ((value, priority_countries), , value), ) end |