Forum: Ruby on Rails [PLUGIN] instance_validations

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2007-01-20 07:26
(Received via mailing list)
Get info at
(until I set up an open svn repository).  Download link is at the
bottom of that page


ActiveRecord lets you define validations at the class level.  This
plugin lets you define validations for ActiveRecord instances.  Take
the following ActiveRecord class:

  class Chicken < ActiveRecord::Base
    include InstanceValidations
    # Has two columns, name and home_town.  Only validate name
    validates_presence_of :name

All instances of Chicken will require a name in order to be valid.  If
you don't define any instance validations, you'll get the expected

  chicken =
  chicken.valid?     => false, will have an error on name

If you do specify instance validations, the class validations are
ignored and only instance validations are used:

  chicken_without_a_name =
  class << chicken_without_a_name
    validates_presence_of :home_town
  chicken_without_a_name.valid?                     => false, will
have an error on home_town but not name
  chicken_without_a_name.home_town = "Roostershire"
  chicken_without_a_name.valid?                     => true

Written by Pat Maddox.  Released under the MIT License.
Get info at
(until I set up an open svn repository)
This topic is locked and can not be replied to.