Validates Xor Presence Of plugin

Plugin details

validates_xor_presence_of adds support for verifying that exactly 1 of multiple attributes are present in a model.

Websitehttp://wiki.pluginaweek.org/Validates_xor_presence_of Repositoryhttp://svn.pluginaweek.org/trunk/plugins/active_record/validations/validates_xor_presence_of/ Author Aaron Pfeifer Tags validation LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.pluginaweek.org/trunk/plugins/active_record/validations/validates_xor_presence_of/

Description
===============

Sometimes your model is defined such that it is only valid if exactly one of a series of attributes is present. For example, a person's location may be defined by a known region (a region_id referencing a regions table) or a custom region (an unknown region). In this case, you may have two columns in your table: region_id and custom_region. If this is the case, validates_xor_presence_of helps ensure that exactly 1 or those 2 attributes is present at any time.

Usage
==========

Example
----------------------

  class Person < ActiveRecord::Base
    validates_xor_presence_of :region_id, :custom_region, :on => :create
  end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago