class Vote < ActiveRecord::Base

  belongs_to :idea
  belongs_to :user

  validates :user, uniqueness: {
    scope: :idea,
    message: "A user cannot vote on the same idea twice."
  }
end

class Vote < ActiveRecord::Base

  self.primary_keys = :idea_id, :user_id

  belongs_to :idea
  belongs_to :user

  validates :user, uniqueness: {
    scope: :idea,
    message: "A user cannot vote on the same idea twice."
  }
end

Add primary keys to Vote model
Add primary keys to Vote model

Specify the 'idea_id' and 'user_id' attributes are to be used as unique
primary keys. Records will be uniquely identified by this composite
key, not the 'id' field created and used by Rails by default.
