开发者

Rails 2.3.x: possible to combine these validations into one?

开发者 https://www.devze.com 2023-01-02 03:34 出处:网络
Is it possible to keep things DRY and put this into one validation line?开发者_如何学编程 validates_presence_of:login

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

精彩评论

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