Disable validations


#1

If a model has validations defined on it and in certain cases I don’t
want some validations to be done then how can I disable the validations
that I don’ want to be done?

model.valid? will do all the validations but I wan’t only some
validations to be done and others to be ignored.

Like a form for create may have some fields in model which can be left
blank, so they should not be validated. But in another form those fields
are present, and the fields which are not present on that screen will
cause validation to fail.

Thanks.


#2

I’m not sure exactly what you’re asking for here, but the standard way
to
only perform validations “sometimes” is by using the :if
argument/option.

validates_uniqueness_of :last_name, :if => :last_name_should_be_unique?

For more information, see:
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html