Skip to content

Instantly share code, notes, and snippets.

Validate nested uniqueness associations

  • Imagine you have 2 models (city and country) with nested attributes feature, then the model country has n cities, the principal validation is that a for each record, the language is unique

Steps:

  • create unique index rails g migration AddIndexToCity
class AddIndexToCity < ActiveRecord::Migration[5.2]