Class: FreeForm::Form
- Inherits:
-
Object
- Object
- FreeForm::Form
- 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
Instance Method Summary collapse
-
#initialize(h = {}) ⇒ Form
constructor
A new instance of Form.
-
#persisted? ⇒ Boolean
Instance Methods —————————————————————————- Required for ActiveModel.
- #save ⇒ Object
- #save! ⇒ Object
Methods included from Validation
Methods included from Property
Methods included from Nested
Methods included from FormInputKey
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
25 |
# File 'lib/freeform/form.rb', line 25 def persisted?; false end |
#save ⇒ Object
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 |