Contextual validations are active __only__ within an appropriate context: either ”create" or ”update”. validates(:name, :presence => true, :on => :create) validates(:name, :presence => {:on => :update}) See http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html#on Should fix https://github.com/couchrest/couchrest_model/pull/90
29 lines
483 B
Ruby
29 lines
483 B
Ruby
# encoding: utf-8
|
|
|
|
module CouchRest #:nodoc:
|
|
module Model #:nodoc:
|
|
|
|
module Callbacks
|
|
extend ActiveSupport::Concern
|
|
included do
|
|
extend ActiveModel::Callbacks
|
|
|
|
define_model_callbacks \
|
|
:create,
|
|
:destroy,
|
|
:save,
|
|
:update
|
|
|
|
end
|
|
|
|
def valid?(context = nil)
|
|
context ||= (new_record? ? :create : :update)
|
|
output = super(context)
|
|
errors.empty? && output
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|