Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/currency_select.rb

Instance Method Summary collapse

Instance Method Details

#currency_options_for_select(selected = nil, priority_currencies = nil) ⇒ Object

Returns a string of option tags for all available currencies. Supply a currency ISO code as selected to have it marked as the selected option tag. You can also supply an array of currencies as priority_currencies, so that they will be listed above the rest of the list.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/currency_select.rb', line 52

def currency_options_for_select(selected = nil, priority_currencies = nil)
  currency_options = "".html_safe

  if priority_currencies
    currency_options += options_for_select(::CurrencySelect::priority_currencies_array(priority_currencies), selected)
    currency_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe

    # 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_currencies.include?(selected)
  end

  # All the countries included in the country_options output.
  return currency_options + options_for_select(::CurrencySelect::currencies_array, selected)
end

#currency_select(object, method, priority_currencies = nil, options = {}, html_options = {}) ⇒ Object

Return select and option tags for the given object and method, using currency_options_for_select to generate the list of option tags.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/currency_select.rb', line 35

def currency_select(object, method, priority_currencies = nil, options = {}, html_options = {})
  tag = if defined?(ActionView::Helpers::InstanceTag) &&
           ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0

           InstanceTag.new(object, method, self, options.delete(:object))
        else
          CurrencySelectTag.new(object, method, self, options)
        end

  tag.to_currency_select_tag(priority_currencies, options, html_options)
end