Class: LotusAdmin::FormBuilder

Inherits:
SimpleForm::FormBuilder
  • Object
show all
Defined in:
lib/lotus_admin/form_builder.rb

Instance Method Summary collapse

Instance Method Details

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



2
3
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
# File 'lib/lotus_admin/form_builder.rb', line 2

def input(attribute_name, options = {}, &block)
  type = options.fetch(:as, nil) || default_input_type(
      attribute_name,
      find_attribute_column(attribute_name),
      options
  )

  if type != :boolean
    if options[:placeholder].nil?
      options[:placeholder] ||= if object.class.respond_to?(:human_attribute_name)
                                  object.class.human_attribute_name(attribute_name.to_s)
                                else
                                  attribute_name.to_s.humanize
                                end
    end
    options[:label] = false if options[:label].nil?
  end

  case type
  when :date
    options[:label] = options[:placeholder]
  when :grouped_select, :select
    options[:include_blank] = "Choose #{ options[:placeholder] }..."
  end

  super
end