跳过对创建方法的验证 [英] Skipping validation on create method
本文介绍了跳过对创建方法的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要跳过对 create 方法的验证.我使用的是 Rails 4 和 ruby 2
I need to skip the validation on create method.I am using Rails 4 and ruby 2
我试过这样
@model.save(:validate => false)
它不起作用
推荐答案
假设你在谈论 ActiveRecord
;在 Rails 3 和 4 中,跳过验证并可能保留无效对象的方法如您所描述的:
Assuming you are talking about ActiveRecord
; In Rails 3 and 4 the way to skip validations and potentially persist invalid objects is as you describe:
@model.save(:validate => false)
在 Rails 2 中你需要做
In Rails 2 you'd need to do
@model.save(false)
这篇关于跳过对创建方法的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文