问题描述
save(false)
和 save(:validate => false)
之间有什么区别?从我可以看出,功能是一样的。使用:validate
的版本在api中,导致我相信 save(false)
是不推荐使用的版本?以下是对我的回应:。该指南中有 save(false)
,但在使用时出现错误。我将其切换到:验证
版本,并且工作正常。
What's the difference between save(false)
and save(:validate => false)
? From what I can tell, the functionality is the same. The version that uses :validate
is in the api which leads me to believe save(false)
is a deprecated version? This came up for me when following this: https://github.com/plataformatec/devise/wiki/How-To:-Create-a-guest-user. The guide has save(false)
in there but I was getting errors when using it. I switched it to the :validate
version and that worked fine.
推荐答案
在Rails之前的版本3之前,保存
,您可以通过 false
来绕过验证。
In Rails versions before than 3, save
was a method in ActiveRecord::Base
and you could pass false
to it in order to bypass validations.
在Rails 3中,保存
被移动到 ActiveRecord :: Persistance
,然后您应该通过:validate => ;为了绕过验证,假
到保存
。
In Rails 3, save
was moved to ActiveRecord::Persistance
and since then you should pass :validate => false
to save
in order to bypass validations.
这篇关于save(false)和save之间的区别(:validate => false)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!