Module: ActionView::Helpers::FormOptionsHelper
- Defined in:
- lib/carmen/action_view_helpers.rb
Instance Method Summary collapse
-
#country_options_for_select(selected = nil, priority_country_codes = nil, options = {}) ⇒ 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.
-
#state_options_for_select(selected = nil, country = Carmen.default_country) ⇒ Object
Returns a string of option tags containing the state names and codes for the specified country code, or nil if the states are not know for that country.
-
#state_select(object, method, country = Carmen.default_country, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using state_options_for_select to generate the list of option tags.
Instance Method Details
#country_options_for_select(selected = nil, priority_country_codes = nil, options = {}) ⇒ 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 a list of country codes as additional parameters, so that they will be listed above the rest of the (long) list.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/carmen/action_view_helpers.rb', line 23 def (selected = nil, priority_country_codes = nil, = {}) = "" unless priority_country_codes.empty? priority_countries = Carmen.countries(.dup).select do |pair| name, code = pair priority_country_codes.include?(code) end unless priority_countries.empty? priority_countries = priority_countries.sort_by { |name, code| priority_country_codes.index(code) } += (priority_countries, selected) += "\n<option value=\"\" disabled=\"disabled\">-------------</option>\n" end end return + (Carmen.countries(), priority_country_codes.include?(selected) ? nil : 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.
10 11 12 |
# File 'lib/carmen/action_view_helpers.rb', line 10 def country_select(object, method, priority_countries = nil, = {}, = {}) InstanceTag.new(object, method, self, .delete(:object)).to_country_select_tag(priority_countries, , ) end |
#state_options_for_select(selected = nil, country = Carmen.default_country) ⇒ Object
Returns a string of option tags containing the state names and codes for the specified country code, or nil if the states are not know for that country. Supply a state code as selected
to have it marked as the selected option tag.
16 17 18 |
# File 'lib/carmen/action_view_helpers.rb', line 16 def (selected = nil, country = Carmen.default_country) (Carmen.states(country), selected) end |
#state_select(object, method, country = Carmen.default_country, options = {}, html_options = {}) ⇒ Object
Return select and option tags for the given object and method, using state_options_for_select to generate the list of option tags.
5 6 7 |
# File 'lib/carmen/action_view_helpers.rb', line 5 def state_select(object, method, country = Carmen.default_country, ={}, ={}) InstanceTag.new(object, method, self, .delete(:object)).to_state_select_tag(country, , ) end |