O'Reilly logo
  • Yuho Ito thinks this is interesting:

The :uniqueness option can also validate whether the value of the specified attributes are unique based on multiple scope parameters. For example, you can use it to make sure a teacher can be on the schedule only once per semester for a particular class:

class Schedule < ActiveRecord::Base
  validates :teacher_id, :uniqueness => { :scope => [:semester_id, :class_id] }
end

From

Cover of Beginning Rails 3

Note

グループごとにユニーク値設定を行う。