1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Prathamesh Sonpatki 2014-09-09 14:46:54 +05:30
parent 793e4aa9b6
commit a91b36f6eb

View file

@ -142,9 +142,14 @@ module ActiveModel
# value. # value.
def validate(*args, &block) def validate(*args, &block)
options = args.extract_options! options = args.extract_options!
valid_keys = [:on, :if, :unless]
if args.all? { |arg| arg.is_a?(Symbol) } 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 end
if options.key?(:on) if options.key?(:on)