我正在使用Rails v2.3
如果我有一个型号:
class car < ActiveRecord::Base
validate :method_1, :method_2, :method_3
...
# custom validation methods
def method_1
...
end
def method_2
...
end
def method_3
...
end
end
Run Code Online (Sandbox Code Playgroud)
如您所见,我有3种自定义验证方法,我将它们用于模型验证.
如果我在这个模型类中有另一个方法,它保存模型的新实例,如下所示:
# "flag" here is NOT a DB based attribute
def save_special_car flag
new_car=Car.new(...)
new_car.save #how to skip validation method_2 if flag==true
end
Run Code Online (Sandbox Code Playgroud)
我想跳过method_2这种保存新车的特定方法的验证,如何跳过某些验证方法?