Class: FreeForm::Form

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks, ActiveModel::Naming, Forwardable
Includes:
ActiveModel::Conversion, ActiveModel::Validations, FormInputKey, Nested, Property, Validation
Defined in:
lib/freeform/form.rb

Instance Attribute Summary

Attributes included from Property

#parent_form

Instance Method Summary collapse

Methods included from Validation

included

Methods included from Property

#assign_params, included

Methods included from Nested

included

Methods included from FormInputKey

included

Constructor Details

#initialize(h = {}) ⇒ Form

Returns a new instance of Form.



27
28
29
30
# File 'lib/freeform/form.rb', line 27

def initialize(h={})
  h.each {|k,v| send("#{k}=",v)}
  initialize_child_models      
end

Instance Method Details

#persisted?Boolean

Instance Methods


Required for ActiveModel

Returns:

  • (Boolean)


25
# File 'lib/freeform/form.rb', line 25

def persisted?; false end

#saveObject



32
33
34
35
36
37
38
39
# File 'lib/freeform/form.rb', line 32

def save
  return false unless valid?

  self.class.models.each do |form_model|
    model = send(form_model)
    model.is_a?(Array) ? model.each { |m| m.save } : save_or_destroy(model)
  end
end

#save!Object



41
42
43
44
45
46
47
48
# File 'lib/freeform/form.rb', line 41

def save!
  raise FreeForm::FormInvalid, "form invalid." unless valid?

  self.class.models.each do |form_model|
    model = send(form_model)
    model.is_a?(Array) ? model.each { |m| m.save! } : save_or_destroy!(model)
  end
end