Forum: Ruby on Rails Disable validations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rm R. (Guest)
on 2007-02-26 23:06
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.
Luke I. (Guest)
on 2007-02-26 23:12
(Received via mailing list)
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/Va...
This topic is locked and can not be replied to.