Permalink
Browse files

Properly deprecate validate_on_#{on}

  • Loading branch information...
1 parent 5987fd4 commit 1318bf6e33fe07bcc9fe50854b0bbb4627e71e88 @wycats wycats committed Aug 3, 2010
Showing with 12 additions and 0 deletions.
  1. +12 −0 activemodel/lib/active_model/validations.rb
@@ -128,6 +128,18 @@ def validate(*args, &block)
set_callback(:validate, *args, &block)
end
+ [:create, :update].each do |type|
+ class_eval <<-RUBY
+ def validate_on_#{type}(*args, &block)
+ msg = "validate_on_#{type} is deprecated. Please use validate(args, :on => :#{type})"
+ ActiveSupport::Deprecation.warn(msg, caller)
+ options = args.last || {}
+ options[:on] = :#{type}
+ validate(args.push(options), &block)
+ end
+ RUBY
+ end
+
# List all validators that are being used to validate the model using
# +validates_with+ method.
def validators

0 comments on commit 1318bf6

Please sign in to comment.