From 1318bf6e33fe07bcc9fe50854b0bbb4627e71e88 Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 3 Aug 2010 11:47:19 -0700 Subject: [PATCH] Properly deprecate validate_on_#{on} --- activemodel/lib/active_model/validations.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 3407c59e7a..32e3cb5b79 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -128,6 +128,18 @@ module ActiveModel 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