Module: Reform::Form::Save

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

Defined Under Namespace

Modules: NestedHash, RecursiveSave

Instance Method Summary collapse

Instance Method Details

#save(&block) ⇒ Object

Returns the result of that save invocation on the model.



18
19
20
21
22
23
24
# File 'lib/reform/form/save.rb', line 18

def save(&block)
  # DISCUSS: we should never hit @mapper here (which writes to the models) when a block is passed.
  return deprecate_first_save_block_arg(&block) if block_given?

  sync_models # recursion
  save!
end

#save!Object



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

def save!
  result = save_model
  mapper.new(fields).extend(RecursiveSave).to_hash # save! on all nested forms.  # TODO: only include nested forms here.
  result
end

#save_modelObject



32
33
34
# File 'lib/reform/form/save.rb', line 32

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



56
57
58
59
60
# File 'lib/reform/form/save.rb', line 56

def to_nested_hash(*)
  map = mapper.new(fields).extend(NestedHash)

  ActiveSupport::HashWithIndifferentAccess.new(map.to_hash)
end