title: Rails nested attributes: validates_uniqueness_of doesn't work
body: <p>I have 3 models:</p>
  
  <pre><code>class UserLanguage &lt; ActiveRecord::Base
      belongs_to :user
      belongs_to :language
  end
  
  class Language &lt; ActiveRecord::Base
      has_many :user_languages
      has_many :users, :through =&gt; :user_languages
  end
  
  class User &lt; ActiveRecord::Base
      has_many :user_languages, :dependent =&gt; :destroy
      has_many :languages, :through =&gt; :user_languages
      accepts_nested_attributes_for :user_languages, :allow_destroy =&gt; true
  end
  </code></pre>
  
  <p>I'm using <a href="https://github.com/ryanb/nested_form" rel="nofollow">nested_form gem</a> to help user select which language(s) they can speak in. The CRUD for that is working fine.</p>
  
  <p>But, I can't validate uniqueness of the UserLanguage. I try this 2 syntax but they didn't work for me:</p>
  
  <pre><code>validates_uniqueness_of :language_id, scope: :user_id
  validates :language_id, :uniqueness =&gt; {:scope =&gt; user_id}
  </code></pre>
  
  <p>My schema for user_languages table:</p>
  
  <pre><code>  create_table "user_languages", force: :cascade do |t|
      t.integer  "user_id"
      t.integer  "language_id"
      t.datetime "created_at",  null: false
      t.datetime "updated_at",  null: false
    end
  
    add_index "user_languages", ["language_id"], name: "index_user_languages_on_language_id", using: :btree
    add_index "user_languages", ["user_id"], name: "index_user_languages_on_user_id", using: :btree
  </code></pre>
  
  <p>What should I do to make sure one user can choose only a language once? Say, if I select English inside the dropdown, my second English will not be saved (duplicate) and rejected.</p>