aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-11-20 22:01:04 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-11-20 22:01:04 +0000
commit8ed83b9b1efbe94728f9b504ff58f06cc41f9fed (patch)
tree07ff26010cf3a2d4617065e592e72c42307424cb /activerecord/lib
parent609a03fd2ad434ea4e5e5418336b3e50dcce3557 (diff)
downloadrails-8ed83b9b1efbe94728f9b504ff58f06cc41f9fed.tar.gz
rails-8ed83b9b1efbe94728f9b504ff58f06cc41f9fed.tar.bz2
rails-8ed83b9b1efbe94728f9b504ff58f06cc41f9fed.zip
validates_inclusion_of and validates_exclusion_of allow formatted :message strings. Closes #8132 [devrieda, Mike Naberezny]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8172 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/validations.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 24b29b1ec8..21d57576f8 100755
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -689,8 +689,9 @@ module ActiveRecord
# Validates whether the value of the specified attribute is available in a particular enumerable object.
#
# class Person < ActiveRecord::Base
- # validates_inclusion_of :gender, :in=>%w( m f ), :message=>"woah! what are you then!??!!"
- # validates_inclusion_of :age, :in=>0..99
+ # validates_inclusion_of :gender, :in => %w( m f ), :message => "woah! what are you then!??!!"
+ # validates_inclusion_of :age, :in => 0..99
+ # validates_inclusion_of :format, :in => %w( jpg gif png ), :message => "extension %s is not included in the list"
# end
#
# Configuration options:
@@ -713,7 +714,7 @@ module ActiveRecord
raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?("include?")
validates_each(attr_names, configuration) do |record, attr_name, value|
- record.errors.add(attr_name, configuration[:message]) unless enum.include?(value)
+ record.errors.add(attr_name, configuration[:message] % value) unless enum.include?(value)
end
end
@@ -722,6 +723,7 @@ module ActiveRecord
# class Person < ActiveRecord::Base
# validates_exclusion_of :username, :in => %w( admin superuser ), :message => "You don't belong here"
# validates_exclusion_of :age, :in => 30..60, :message => "This site is only for under 30 and over 60"
+ # validates_exclusion_of :format, :in => %w( mov avi ), :message => "extension %s is not allowed"
# end
#
# Configuration options:
@@ -744,7 +746,7 @@ module ActiveRecord
raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?("include?")
validates_each(attr_names, configuration) do |record, attr_name, value|
- record.errors.add(attr_name, configuration[:message]) if enum.include?(value)
+ record.errors.add(attr_name, configuration[:message] % value) if enum.include?(value)
end
end