Class: WhyValidationsSuckIn96::ValidatesAcceptance

Inherits:
WhyValidationsSuckIn96::Validation show all
Includes:
WhyValidationsSuckIn96::AttributeBasedValidation, WhyValidationsSuckIn96::SkippableValidation
Defined in:
lib/whyvalidationssuckin96/macros/validates_acceptance.rb

Overview

Validates the acceptance of an attribute, such as the “I agree to the terms and conditions” checkbox value returned by a form post.

Examples:

Default usage

  setup_validations do
    validates_acceptance_of :privacy_policy, :terms_and_conditions
  end

Changing the :accept value

  setup_validations do
    validates_acceptance_of :privacy_policy, :accept => "yep"
  end

Constant Summary

DefaultOptions =
{:allow_nil => true, :accept => "1", :message => "must be accepted"}

Constants inherited from WhyValidationsSuckIn96::Validation

DefaultOptions

Instance Method Summary

Methods included from WhyValidationsSuckIn96::AttributeBasedValidation

#attribute, #attribute_value, #initialize

Methods inherited from WhyValidationsSuckIn96::Validation

#failed?, #has_run?, #initialize, #message, new_subclass, #passed?, #validates?

Constructor Details

This class inherits a constructor from WhyValidationsSuckIn96::AttributeBasedValidation

Instance Method Details

- (Object) validate



24
25
26
27
28
29
30
31
# File 'lib/whyvalidationssuckin96/macros/validates_acceptance.rb', line 24

def validate
  super
  if options[:accept] == attribute_value
    pass
  else
    fail
  end
end