Module: Reform::Form::Save

Included in:
Reform::Form
Defined in:
lib/reform/form/save.rb

Instance Method Summary collapse

Instance Method Details

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

Returns the result of that save invocation on the model.



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

def save(options={}, &block)
  # DISCUSS: we should never hit @mapper here (which writes to the models) when a block is passed.
  return yield to_nested_hash if block_given?

  sync_models # recursion
  save!(options)
end

#save!(options = {}) ⇒ Object

FIXME.



11
12
13
14
15
16
17
18
19
# File 'lib/reform/form/save.rb', line 11

def save!(options={}) # FIXME.
  result = save_model

  save_representer.new(fields).to_hash # save! on all nested forms.

  dynamic_save!(options)

  result
end

#save_modelObject



21
22
23
# File 'lib/reform/form/save.rb', line 21

def save_model
  model.save # TODO: implement nested (that should really be done by Twin/AR).
end

#to_nested_hashObject Also known as: to_hash



27
28
29
# File 'lib/reform/form/save.rb', line 27

def to_nested_hash(*)
  ActiveSupport::HashWithIndifferentAccess.new(nested_hash_representer.new(fields).to_hash)
end