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

#saveObject



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

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

  sync_models # recursion
  save!
end

#save!Object



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

def save!
  save_model
  mapper.new(self).extend(RecursiveSave).to_hash # save! on all nested forms.
end

#save_modelObject



30
31
32
# File 'lib/reform/form/save.rb', line 30

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

#to_nested_hashObject



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

def to_nested_hash
  source = deprecate_potential_readers_used_in_sync_or_save(fields) # TODO: remove in 1.1.

  map = mapper.new(source).extend(NestedHash)

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