Sha256: 614d9b01ed1bea74d4cf048bad3c687d0a936b102900e229ddc4b09a77c62e31

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

# UniqueNestedValidator

This validator allows you to verify the uniqueness of attributes from nested models.

## Installation

Add this line to your application's Gemfile:

    gem 'unique_nested_validator'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install unique_nested_validator

## Usage


Let's say you have a model for `Runner`:

    class Runner < ActiveRecord::Base
      attr_accessible :email

Then you create a `Race` and fill in runners using nested forms. In your `Race` model you will accept nested attributes for the nested model `Runner`:

    class Race < ActiveRecord::Base
      has_many :runners, :dependent => :destroy
      accepts_nested_attributes_for :products

If we want to warrant that there aren't two runners with the same id, so we add the following validation to `Race`:

      validates :products, :unique_nested => true

Or, if we want to warrant there aren't repeated emails for runners we add the following validation:

      validates :products, :unique_nested => { :with => :email }

And it is possible to set a custom error message:

      validates :products, :unique_nested => { :with => :email, :message => "Two runners cannot have the same email" }


## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unique_nested_validator-1.0.1 README.md
unique_nested_validator-1.0.0 README.md