Class: BaseForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModelAttributes
Defined in:
app/forms/base_form.rb

Overview

An abstract form object for the application, defining any common interfaces and providing the base functionality (attribute management and validation) for any sub forms

Note that this uses an external gem called 'active_model_attributes' - this is because the rails project has added an attributes API to active model, but only implemented it in active record for now. It is assumed that the rails project will implement it in active model itself in the future, in the same way it is implemented in active record. This gem fills in the gap for now, but can hopefully be removed in a future version of rails.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attribute?(attr) ⇒ Boolean

Indicates if the form has an attribute defined


45
46
47
# File 'app/forms/base_form.rb', line 45

def self.attribute?(attr)
  attributes_registry.keys.include?(attr)
end

.new_ignoring_extras(attrs = {}) ⇒ Object


37
38
39
40
# File 'app/forms/base_form.rb', line 37

def self.new_ignoring_extras(attrs = {})
  new_attrs = attrs.slice(*attributes_registry.keys)
  new(new_attrs)
end

.typeSymbol

The unique type code for the form

Raises:

  • (NotImplementedError)

21
22
23
# File 'app/forms/base_form.rb', line 21

def self.type
  raise NotImplementedError
end

Instance Method Details

#exportHash

Exports the contents of the form as a hash with symbolized top level keys


33
34
35
# File 'app/forms/base_form.rb', line 33

def export
  export_params
end

#typeObject

See @self.class.type


26
27
28
# File 'app/forms/base_form.rb', line 26

def type
  self.class.type
end

#valid?Boolean

Indicates if the model passes all validations


# File 'app/forms/base_form.rb', line 14