save(false)和save之间的区别(:validate => false) [英] Difference between save(false) and save(:validate => false)

查看:316
本文介绍了save(false)和save之间的区别(:validate => false)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

save(false) save(:validate => false)之间有什么区别?从我可以看出,功能是一样的。使用:validate 的版本在api中,导致我相信 save(false)是不推荐使用的版本?以下是对我的回应: https:/ /github.com/plataformatec/devise/wiki/How-To:-Create-a-guest-user 。该指南中有 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之前,保存 ActiveRecord :: Base 中的方法,您可以通过 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆