Class: ActiveAdmin::HasManyBuilder

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/active_admin/form_builder.rb

Overview

Decorates a FormBuilder with the additional attributes and methods to build a has_many block. Nested has_many blocks are handled by nested decorators.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(has_many_form, assoc, options) ⇒ HasManyBuilder

Returns a new instance of HasManyBuilder.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_admin/form_builder.rb', line 47

def initialize(has_many_form, assoc, options)
  super has_many_form
  @assoc = assoc
  @options = extract_custom_settings!(options.dup)
  @options.reverse_merge!(for: assoc)
  @options[:class] = [options[:class], "inputs has-many-fields"].compact.join(" ")

  if sortable_column
    @options[:for] = [assoc, sorted_children(sortable_column)]
  end
end

Instance Attribute Details

#assocObject (readonly)

Returns the value of attribute assoc.



42
43
44
# File 'lib/active_admin/form_builder.rb', line 42

def assoc
  @assoc
end

#destroy_optionObject (readonly)

Returns the value of attribute destroy_option.



45
46
47
# File 'lib/active_admin/form_builder.rb', line 45

def destroy_option
  @destroy_option
end

#headingObject (readonly)

Returns the value of attribute heading.



44
45
46
# File 'lib/active_admin/form_builder.rb', line 44

def heading
  @heading
end

#new_recordObject (readonly)

Returns the value of attribute new_record.



45
46
47
# File 'lib/active_admin/form_builder.rb', line 45

def new_record
  @new_record
end

#optionsObject (readonly)

Returns the value of attribute options.



43
44
45
# File 'lib/active_admin/form_builder.rb', line 43

def options
  @options
end

#remove_recordObject (readonly)

Returns the value of attribute remove_record.



45
46
47
# File 'lib/active_admin/form_builder.rb', line 45

def remove_record
  @remove_record
end

#sortable_columnObject (readonly)

Returns the value of attribute sortable_column.



44
45
46
# File 'lib/active_admin/form_builder.rb', line 44

def sortable_column
  @sortable_column
end

#sortable_startObject (readonly)

Returns the value of attribute sortable_start.



44
45
46
# File 'lib/active_admin/form_builder.rb', line 44

def sortable_start
  @sortable_start
end

Instance Method Details

#render(&block) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/active_admin/form_builder.rb', line 59

def render(&block)
  html = "".html_safe
  html << template.(:h3, class: "has-many-fields-title") { heading } if heading.present?
  html << template.capture { content_has_many(&block) }
  html = wrap_div_or_li(html)
  template.concat(html) if template.output_buffer
  html
end