Class: Edifice::Forms::FormModel
- Inherits:
-
Object
- Object
- Edifice::Forms::FormModel
- Extended by:
- ActiveModel::Callbacks, ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- lib/edifice-forms/form_model.rb
Defined Under Namespace
Classes: RecordInvalid
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ FormModel
constructor
A new instance of FormModel.
- #persisted? ⇒ Boolean
-
#save ⇒ Object
default implementation, override as necessary.
- #save! ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ FormModel
Returns a new instance of FormModel.
22 23 24 |
# File 'lib/edifice-forms/form_model.rb', line 22 def initialize(attributes = {}) attributes.each { |n, v| send("#{n}=", v) if respond_to?("#{n}=") } end |
Class Method Details
.create(attributes = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/edifice-forms/form_model.rb', line 37 def self.create(attributes = {}) form = new(attributes) form.save form end |
Instance Method Details
#persisted? ⇒ Boolean
43 44 45 |
# File 'lib/edifice-forms/form_model.rb', line 43 def persisted? false end |
#save ⇒ Object
default implementation, override as necessary
27 28 29 30 31 |
# File 'lib/edifice-forms/form_model.rb', line 27 def save run_callbacks :save do valid? end end |
#save! ⇒ Object
33 34 35 |
# File 'lib/edifice-forms/form_model.rb', line 33 def save! save || raise(RecordInvalid.new(self)) end |