Class: CustomFormBuilder

Inherits:
SimpleForm::FormBuilder
  • Object
show all
Defined in:
app/inputs/custom_form_builder.rb

Instance Method Summary collapse

Constructor Details

#initializeCustomFormBuilder

Returns a new instance of CustomFormBuilder.



2
3
4
# File 'app/inputs/custom_form_builder.rb', line 2

def initialize(*)
  super
end

Instance Method Details

#association(association, options = {}, &block) ⇒ Object



6
7
8
9
# File 'app/inputs/custom_form_builder.rb', line 6

def association(association, options = {}, &block)
  resolve_custom_input_association(association, options)
  super(association, options, &block)
end

#resolve_custom_input_association(association, options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/inputs/custom_form_builder.rb', line 11

def resolve_custom_input_association(association, options)
  return if options[:as].present?

  [
    "#{object.class.name.demodulize.underscore}_#{association.to_s}".to_sym, association
  ].each do |key|
    camelized = "#{key.to_s.camelize}Input"
    mapping = attempt_mapping_with_custom_namespace(camelized) ||
              attempt_mapping(camelized, Object) ||
              attempt_mapping(camelized, self.class)

    next unless mapping.present?

    options[:as] = key
    break
  end
end