开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜