Module: ActionView::Helpers::FormOptionsHelper
- Defined in:
- lib/uncharted/extensions/rails.rb
Instance Method Summary collapse
-
#country_options_for_select(selected = nil, priority_countries = nil) ⇒ Object
Returns a string of option tags for pretty much any country in the world.
-
#country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
-
#teritory_select(object, method, priority_territories = nil, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
- #territory_options_for_select(selected = nil, priority_territories = nil) ⇒ Object
Instance Method Details
#country_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.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/uncharted/extensions/rails.rb', line 21 def (selected = nil, priority_countries = nil) = "" if priority_countries += (Country.find(priority_countries), :alpha2, :name, selected) += "<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 + (Uncharted::Country.countries, :alpha2, :name, selected) end |
#country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
7 8 9 |
# File 'lib/uncharted/extensions/rails.rb', line 7 def country_select(object, method, priority_countries = nil, = {}, = {}) InstanceTag.new(object, method, self, .delete(:object)).to_country_select_tag(priority_countries, , ) end |
#teritory_select(object, method, priority_territories = nil, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
12 13 14 |
# File 'lib/uncharted/extensions/rails.rb', line 12 def teritory_select(object, method, priority_territories = nil, = {}, = {}) InstanceTag.new(object, method, self, .delete(:object)).to_territory_select_tag(priority_territories, , ) end |
#territory_options_for_select(selected = nil, priority_territories = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/uncharted/extensions/rails.rb', line 35 def (selected = nil, priority_territories = nil) = "" if priority_territories += (Territory.find(priority_territories), :code, :name, selected) += "<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_territories.include?(selected) end + (Uncharted::Country.territories, :code, :name, selected) end |