Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/subdivision_select/subdivision_select_helper.rb

Instance Method Summary collapse

Instance Method Details

#subdivision_select(method, country_or_options = {}, options = {}, html_options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/subdivision_select/subdivision_select_helper.rb', line 4

def subdivision_select(method, country_or_options = {}, options = {}, html_options = {})
  # Shift args, if necessary
  if Hash === country_or_options
    html_options = options
    options = country_or_options
  else
    country = country_or_options
  end

  options.merge!({ object: @object })

  # Add class (that JS uses)
  if html_options["class"].present?
    html_options["class"] += " subdivision-selector"
  else
    html_options["class"] = "subdivision-selector"
  end

  subdivision_select_hidden_field(method).render + Tags::Select.new(
    @object_name,
    method,
    @template,
    SubdivisionSelect::SubdivisionsHelper::get_subdivisions_for_select(country),
    options,
    html_options
  ).render
end