views:

339

answers:

1

Hi folks,

I use Rails 3.0.0.beta4

I want to add a validation on uniqueness on two attributes, that means that my model is valid if the couple of 'recorded_at' and 'zipcode' is unique.

On one attribute here is the syntax

validates :zipcode, :uniqueness => true

thanks

+1  A: 

In Rails 2, I would have written:

validates_uniqueness_of :zipcode, :scope => :recorded_at

In Rails 3:

validates :zipcode, :uniqueness => {:scope => :recorded_at}
Christian Lescuyer
I would say that logically it makes more sense to say that you require `recorded_at` to be unique within the scope of a zipcode. `validate :recorded_at, : uniqueness => { :scope => :zipcode }`
Ariejan