Forum: Ruby on Rails Cancel validation in subclass

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.
eric (Guest)
on 2005-11-27 07:53
(Received via mailing list)
Quick question,

I have a class which has a validates* declaration to validate the model.
Specifically it has a validates_presence_of declaration. In a subclass
of that class I want to get rid of this validation. Is there a way a
validation can be removed?

Eric
t.lucas (Guest)
on 2005-11-27 16:50
(Received via mailing list)
On 27/11/2005, at 4:41 PM, Eric A. wrote:

> I have a class which has a validates* declaration to validate the
> model. Specifically it has a validates_presence_of declaration. In
> a subclass of that class I want to get rid of this validation. Is
> there a way a validation can be removed?

class Upper < ActiveRecord::Base

     validates_presence_of :imported_beer, :if => :upper_class

     protected

     def upper_class(yuppie)
         yuppie.class == Upper
     end

end

-- tim
This topic is locked and can not be replied to.