views:

36

answers:

2

Is it possible to keep things DRY and put this into one validation line?

  validates_presence_of     :login
  validates_uniqueness_of   :login
+5  A: 

You actually can just remove the validates_presence_of line, because validates_uniqueness_of defaults to :allow_blank => false (and :allow_nil => false)

Take a look at the docs here .

x1a4
A: 

In Rails 3 (which is not released yet, but please do try out the beta) you can!

validates :login, :presence => true, :uniqueness => true
Ryan Bigg