views:

21

answers:

1

Hi,

In a Ruby on Rails 3 application, I have invitations. Here is the model:

class TeamInvitation < ActiveRecord::Base
  belongs_to :team

  validates :email, :presence => true, :format => RFC822::EMAIL
  validates_uniqueness_of :email, :scope => :team_id
end

How can I refactor the uniqueness validation to include it into the validates method?

According to the documentation, the key :uniqueness should be a boolean, but in my case i want specify the scope. How can I do that (if possible)?

A: 

Have you tried this?

:uniqueness => { :scope => :team_id }

I haven't, but I know other ones can accept a hash. Might be worth a shot.

James