Class: Trestle::Form::Builder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/trestle/form/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



30
31
32
33
34
35
36
# File 'lib/trestle/form/builder.rb', line 30

def method_missing(name, *args, &block)
  if field = self.class.fields[name]
    field.new(self, @template, *args, &block).render
  else
    super
  end
end

Class Method Details

.register(name, klass) ⇒ Object



20
21
22
23
# File 'lib/trestle/form/builder.rb', line 20

def self.register(name, klass)
  rename_existing_helper_method(name)
  self.fields[name] = klass
end

Instance Method Details

#errors(name) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/trestle/form/builder.rb', line 12

def errors(name)
  if object.respond_to?(:errors) && object.errors.respond_to?(:[])
    object.errors[name].to_a
  else
    []
  end
end