From a91b36f6eb502e91c9e3e2e8d3db26abc56696cf Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Tue, 9 Sep 2014 14:46:54 +0530 Subject: Update error message for validate method - Improve the error message by suggesting that the user may have intended to call validates instead of validate method. --- activemodel/lib/active_model/validations.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 7ee033ba5f..08c2b02f19 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -142,9 +142,14 @@ module ActiveModel # value. def validate(*args, &block) options = args.extract_options! + valid_keys = [:on, :if, :unless] if args.all? { |arg| arg.is_a?(Symbol) } - options.assert_valid_keys([:on, :if, :unless]) + options.each_key do |k| + unless valid_keys.include?(k) + raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}. Perhaps you meant to call validates instead of validate.") + end + end end if options.key?(:on) -- cgit v1.2.3