If you a trying to validate if the value of an attribute is unique on the database, you can easily accomplish this by using the built in helper method…
validates_uniqueness_ofBut how would you go about making sure the attribute value is unique based on a scope parameter? Let’s say you are building a holidays table and need to make sure you only allow one ‘Christmas’ holiday to be created per year:
validates_uniqueness_of :name, :scope => :year, :message => "must be unique"
Hope that helps!