[英]Is `validates_presence_of` deprecated (as of Rails 3)?
According the the Rails 3 release notes, validate_presence_of
is deprecated . 根据Rails 3发行说明,
validate_presence_of
已弃用 。
However, I can see no mention of this in the documentation (for v4.0.2) . 但是,在文档中(对于v4.0.2) ,我看不到任何提及。
Was this an error in the release notes/did it get re-precated/is the documentation wrong? 这是发行说明中的错误/是否已被重新使用/文档是否错误?
It's a soft deprecation. 这是一种软弃用。 Both syntaxes still exist, but the
validates
is newer and 'preferred'. 两种语法仍然存在,但是
validates
是较新的并且是“首选”的。
The method is still there, but since Rails 3 it is defined in a slightly different namespace than before. 该方法仍然存在,但是由于Rails 3的定义,其命名空间与以前略有不同。
Before Rails 3: 在Rails 3之前:
ActiveModel::Validations::ClassMethods#validates_presence_of
Since Rails 3: 从Rails 3:
ActiveRecord::Validations::ClassMethods#validates_presence_of
ActiveModel::Validations::HelperMethods#validates_presence_of
I had to look very close to see the differences. 我必须非常仔细地观察差异。
Conclusion: just keep using validates_presence_of
! 结论:只需继续使用
validates_presence_of
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.