I have a problem with the scoped uniqueness validation in Rails for nested attributes with a parent of parent.
Background
I have a rails 4 appl
I'll supply one possible solution. Not tested, but it should work, with a custom validation and an extra association.
In your Account
model:
has_many :email_addresses, through: :contacts
In your EmailAddress
model:
validate :uniqueness_of_mail
private
def uniqueness_of_mail
account = contact.account
if account.email_addresses.map(&:email).includes? email
errors.add(email, 'Contact already has this email address')
false
else
true
end
end