diff options
author | Jeroen van Dijk <jeroen@jeevidee.nl> | 2010-05-15 19:43:45 +0200 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-05-15 11:17:58 -0700 |
commit | bc1c8d58ec45593acba614d1d0fecb49adef08ff (patch) | |
tree | 5515d6211f61cc86804a6580b9d2ec1c710b9db0 /activemodel/lib/active_model/validations/length.rb | |
parent | 47c9a355062888feb2c7ea7c794e914a9b78f50c (diff) | |
download | rails-bc1c8d58ec45593acba614d1d0fecb49adef08ff.tar.gz rails-bc1c8d58ec45593acba614d1d0fecb49adef08ff.tar.bz2 rails-bc1c8d58ec45593acba614d1d0fecb49adef08ff.zip |
Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options.
This makes it possible to pass additional options through Validators to message
generation. E.g. plugin authors want to add validates_presence_of :foo, :format
=> "some format".
Also, cleanup the :default vs :message options confusion in ActiveModel
validation message generation.
Also, deprecate ActiveModel::Errors#add_on_blank(attributes, custom_message) in
favor of ActiveModel::Errors#add_on_blank(attributes, options).
Original patch by Sven Fuchs, some minor changes and has been changed to be applicable to master again
[#4057 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activemodel/lib/active_model/validations/length.rb')
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index d7218f4f52..9b671f58de 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -37,7 +37,7 @@ module ActiveModel CHECKS.each do |key, validity_check| next unless check_value = options[key] - custom_message = options[:message] || options[MESSAGES[key]] + options[:message] ||= options[MESSAGES[key]] if options[MESSAGES[key]] valid_value = if key == :maximum value.nil? || value.size.send(validity_check, check_value) @@ -46,7 +46,7 @@ module ActiveModel end next if valid_value - record.errors.add(attribute, MESSAGES[key], :default => custom_message, :count => check_value) + record.errors.add(attribute, MESSAGES[key], options.merge(:count => check_value)) end end end |