我用Rails v2.3
如果我有model:
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
正如你在上面看到的,我有3 custom validation methods个,我用它们来验证模型.
如果我在这个模型类中有另一个方法保存模型的新实例,如下所示:
# "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
我想跳过method_2
的验证,在这个节省新车的特殊方法中,how to skip the certain validation method?