Class: CaringForm::FormBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FormBuilder

Returns a new instance of FormBuilder.



9
10
11
12
13
# File 'lib/caring_form/form_builder.rb', line 9

def initialize(*args)
  @form = args[1]
  @builder = SimpleForm::FormBuilder.new(*args)
  @builder.class.mappings[:string_inline_error] = TextFieldInlineErrorField
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



32
33
34
35
# File 'lib/caring_form/form_builder.rb', line 32

def method_missing(meth, *args, &blk)
  return super unless @builder.respond_to?(meth)
  @builder.send(meth, *args, &blk)
end

Instance Method Details

#field(*names) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/caring_form/form_builder.rb', line 24

def field(*names)
  options = names.extract_options!
  html_list = select_fields!(names, options).map do |field|
    field.render(@form, @builder, options)
  end
  html_list.join("\n").html_safe
end

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



19
20
21
22
# File 'lib/caring_form/form_builder.rb', line 19

def fields(options = {}, &block)
  tag = options.delete(:tag) || :ol
  @builder.template.(tag, options, &block)
end

#metadata(options = {}) ⇒ Object



15
16
17
# File 'lib/caring_form/form_builder.rb', line 15

def (options = {})
  field(:all, options.merge(:filter_type => [:metadata, :dummy]))
end