No commit activity in last 3 years
No release in over 3 years
A uniqueness validator for nested attributes. This gem solves the problem described in https://github.com/rails/rails/issues/4568.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.8

Runtime

 Project Readme

NestedAttributesUniquenessValidator¶ ↑

Description¶ ↑

Uniqueness validator for nested attributes. This gem solves the problem described in github.com/rails/rails/issues/4568.

Installation¶ ↑

# in Gemfile
gem 'nested_attributes_uniqueness_validator'

# Run bundler
$ bundle install

Usage¶ ↑

class Person < ActiveRecord::Base
  has_many :contacts

  validates :contacts, nested_attributes_uniqueness: { scope: [:person_id, :phone] }

  accepts_nested_attributes_for :contacts
end

class Contact < ActiveRecord::Base
  belongs_to :person
end

Options¶ ↑

scope: Attributes that make up the scope of uniqueness. Required.
allow_destroyed: Consider records marked for destruction. Default: false.
allow_blank: Consider blank fields. Default: false.
attribute: Field that will receive the error message. Default: first attribute scope.
message: Error message. Default: taken.