Module: Reform::Form::ActiveModel::FormBuilderMethods

Defined in:
lib/reform/form/active_model.rb

Overview

TODO: rename to FormBuilderCompat.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
# File 'lib/reform/form/active_model.rb', line 3

def self.included(base)
  base.class_eval do
    extend ClassMethods # ::model_name
  end
end

Instance Method Details

#validate(params) ⇒ Object

Modify the incoming Rails params hash to be representable compliant.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/reform/form/active_model.rb', line 23

def validate(params)
  # DISCUSS: #validate should actually expect the complete params hash and then pick the right key as it knows the form name.
  # however, this would cause confusion?
  mapper.new(self).nested_forms do |attr, model| # FIXME: make this simpler.
    if attr.options[:form_collection] # FIXME: why no array?
      params[attr.name] = params["#{attr.name}_attributes"].values
    else
      params[attr.name] = params["#{attr.name}_attributes"]# DISCUSS: delete old key? override existing?
    end
  end

  super
end