Module: WonderfulSimpleForms::SimpleForm::BuilderExtension

Defined in:
lib/wonderful_simple_forms/simple_form.rb

Instance Method Summary collapse

Instance Method Details

#default_input_type_with_belongs_to(*args, &block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/wonderful_simple_forms/simple_form.rb', line 14

def default_input_type_with_belongs_to(*args, &block)
  att_name = (args.first || "#{@attribute_name}").to_s
  options = args.last
  return :belongs_to if (
    object.class.reflect_on_all_associations(:belongs_to).any? { |a| a.name == args.first })

  default_input_type_without_belongs_to(*args, &block)
end

#default_input_type_with_enum(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/wonderful_simple_forms/simple_form.rb', line 5

def default_input_type_with_enum(*args, &block)
  att_name = (args.first || @attribute_name).to_s
  options = args.last
  return :enum if (options.is_a?(Hash) ? options[:as] : @options[:as]).nil? &&
                  is_enum_attributes?( att_name )

  default_input_type_without_enum(*args, &block)
end

#is_enum_attributes?(attribute_name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/wonderful_simple_forms/simple_form.rb', line 23

def is_enum_attributes?( attribute_name )
  object.class.respond_to?(:defined_enums) &&
    object.class.defined_enums.key?(attribute_name) &&
    attribute_name.pluralize != "references"
end