diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2014-09-09 14:46:54 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2014-09-20 22:48:52 +0900 |
commit | a91b36f6eb502e91c9e3e2e8d3db26abc56696cf (patch) | |
tree | ce9d44720fb0ab5799eb7ec818194e39757f3130 /activemodel/lib | |
parent | 793e4aa9b63a066d0bf0dbd291969ec9cd2fc204 (diff) | |
download | rails-a91b36f6eb502e91c9e3e2e8d3db26abc56696cf.tar.gz rails-a91b36f6eb502e91c9e3e2e8d3db26abc56696cf.tar.bz2 rails-a91b36f6eb502e91c9e3e2e8d3db26abc56696cf.zip |
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.
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 7 |
1 files changed, 6 insertions, 1 deletions
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) |