From d5b67ed8d33dbde44d24d7d93135261062e550d1 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 17 Apr 2005 10:04:07 +0000 Subject: Added the option to specify the acceptance string in validates_acceptance_of #1106 [caleb@aei-tech.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1188 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/validations.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index ad951b9c25..af92ac6db8 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -291,16 +291,18 @@ module ActiveRecord # Configuration options: # * message - A custom error message (default is: "can't be empty") # * on - Specifies when this validation is active (default is :save, other options :create, :update) + # * accept - Specifies value that is considered accepted. The default value is a string "1", which + # makes it easy to relate to an HTML checkbox. # - # NOTE: The agreement is considered valid if it's set to the string "1". This makes it easy to relate it to an HTML checkbox. + def validates_acceptance_of(*attr_names) - configuration = { :message => ActiveRecord::Errors.default_error_messages[:accepted], :on => :save, :allow_nil => true } + configuration = { :message => ActiveRecord::Errors.default_error_messages[:accepted], :on => :save, :allow_nil => true, :accept => "1" } configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) attr_accessor *attr_names validates_each(attr_names,configuration) do |record, attr_name, value| - record.errors.add(attr_name, configuration[:message]) unless value == "1" + record.errors.add(attr_name, configuration[:message]) unless value == configuration[:accept] end end -- cgit v1.2.3