lib/edifice/form_model.rb in edifice-0.10.1 vs lib/edifice/form_model.rb in edifice-0.10.2
- old
+ new
@@ -3,16 +3,18 @@
module Edifice
class FormModel
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
+ extend ActiveModel::Callbacks
+ define_model_callbacks :save
# more or less the same as activerecord's one
class RecordInvalid < Exception
attr_reader :record
def initialize(record)
- @model = record
+ @record = record
errors = @record.errors.full_messages.join(", ")
super(errors)
end
end
@@ -20,10 +22,12 @@
attributes.each { |n, v| send("#{n}=", v) if respond_to?("#{n}=") }
end
# default implementation, override as necessary
def save
- valid?
+ run_callbacks :save do
+ valid?
+ end
end
def save!
save || raise(RecordInvalid.new(self))
end
\ No newline at end of file