Module: CountrySelect::TagHelper

Includes:
ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::Tags::SelectRenderer
Included in:
ActionView::Helpers::Tags::CountrySelect
Defined in:
lib/country_select/tag_helper.rb

Instance Method Summary collapse

Methods included from ActionView::Helpers::FormOptionsHelper

#country_select

Instance Method Details

#country_option_tagsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/country_select/tag_helper.rb', line 12

def country_option_tags
  # In Rails 5.2+, `value` accepts no arguments and must also be called
  # with parens to avoid the local variable of the same name
  # https://github.com/rails/rails/pull/29791
  selected_option = @options.fetch(:selected) do
    if self.method(:value).arity.zero?
      value()
    else
      value(@object)
    end
  end

  option_tags_options = {
    selected: selected_option,
    disabled: @options[:disabled]
  }

  if priority_countries.present?
    options_for_select_with_priority_countries(country_options, option_tags_options)
  else
    options_for_select(country_options, option_tags_options)
  end
end