Rails 2.3.x: possible to combine these validations into one?
Is it possible to keep things DRY and put this into one validation line?
开发者_如何学编程 validates_presence_of :login
validates_uniqueness_of :login
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 .
In Rails 3 (which is not released yet, but please do try out the beta) you can!
validates :login, :presence => true, :uniqueness => true
精彩评论