No commit activity in last 3 years
No release in over 3 years
This validator allows you to verify nested models created with nested forms to validate the uniqueness of an attribute, More details in http://github.com/evedovelli/unique_nested_validator
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

 Project Readme

UniqueNestedValidator

Gem Version Build Status Code Climate

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