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

Minor doc changes to active_model/validations/acceptance.rb

This commit is contained in:
Rizwan Reza 2010-06-15 22:13:30 +04:30
parent 538b7b97bb
commit 6907bfe1ab

View file

@ -1,4 +1,6 @@
module ActiveModel module ActiveModel
# == Active Model Acceptance Validator
module Validations module Validations
class AcceptanceValidator < EachValidator class AcceptanceValidator < EachValidator
def initialize(options) def initialize(options)
@ -22,29 +24,42 @@ module ActiveModel
end end
module HelperMethods module HelperMethods
# Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement). Example: # Encapsulates the pattern of wanting to validate the acceptance of a
# terms of service check box (or similar agreement). Example:
# #
# class Person < ActiveRecord::Base # class Person < ActiveRecord::Base
# validates_acceptance_of :terms_of_service # validates_acceptance_of :terms_of_service
# validates_acceptance_of :eula, :message => "must be abided" # validates_acceptance_of :eula, :message => "must be abided"
# end # end
# #
# If the database column does not exist, the +terms_of_service+ attribute is entirely virtual. This check is # If the database column does not exist, the +terms_of_service+ attribute
# performed only if +terms_of_service+ is not +nil+ and by default on save. # is entirely virtual. This check is performed only if +terms_of_service+
# is not +nil+ and by default on save.
# #
# Configuration options: # Configuration options:
# * <tt>:message</tt> - A custom error message (default is: "must be accepted"). # * <tt>:message</tt> - A custom error message (default is: "must be
# * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>). # accepted").
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is true). # * <tt>:on</tt> - Specifies when this validation is active (default is
# * <tt>:accept</tt> - Specifies value that is considered accepted. The default value is a string "1", which # <tt>:save</tt>, other options are <tt>:create</tt> and
# makes it easy to relate to an HTML checkbox. This should be set to +true+ if you are validating a database # <tt>:update</tt>).
# column, since the attribute is typecast from "1" to +true+ before validation. # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should # is true).
# occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The # * <tt>:accept</tt> - Specifies value that is considered accepted.
# method, proc or string should return or evaluate to a true or false value. # The default value is a string "1", which makes it easy to relate to
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should # an HTML checkbox. This should be set to +true+ if you are validating
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The # a database column, since the attribute is typecast from "1" to +true+
# method, proc or string should return or evaluate to a true or false value. # before validation.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
# if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
# or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false
# value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
# determine if the validation should not occur (for example,
# <tt>:unless => :skip_validation</tt>, or
# <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>).
# The method, proc or string should return or evaluate to a true or
# false value.
def validates_acceptance_of(*attr_names) def validates_acceptance_of(*attr_names)
validates_with AcceptanceValidator, _merge_attributes(attr_names) validates_with AcceptanceValidator, _merge_attributes(attr_names)
end end