Module: Bard::TagField::FormBuilder

Defined in:
lib/bard/tag_field/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#tag_field(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object



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/bard/tag_field/form_builder.rb', line 6

def tag_field method, choices = nil, options = {}, html_options = {}, &block
  # Handle different method signatures to match Rails select helper
  case choices
  when Hash
    # tag_field(:method, { class: "form-control" })
    html_options = options
    options = choices
    choices = nil
  when Array
    # tag_field(:method, choices_array, { class: "form-control" })
    html_options = options if options.is_a?(Hash)
  when NilClass
    # tag_field(:method)
    html_options = options
    options = {}
  end

  # Merge options and html_options for Rails compatibility
  merged_options = objectify_options(options.merge(html_options))

  # Pass choices to the Field class
  merged_options[:choices] = choices if choices

  Field.new(@object_name, method, @template, merged_options).render(&block)
end