Forum: Ruby on Rails ActiveRecord: removing validations or callbacks on a subclas

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.
Robert J. (Guest)
on 2007-05-01 00:45
(Received via mailing list)
Often a parent class has validations (or callbacks or associations)
which I don't want the subclass to have.  Is there any simple way to
remove these?
Rick O. (Guest)
on 2007-05-01 01:23
(Received via mailing list)
On 4/30/07, S. Robert J. <removed_email_address@domain.invalid> wrote:
>
> Often a parent class has validations (or callbacks or associations)
> which I don't want the subclass to have.  Is there any simple way to
> remove these?

Not really.  Just don't add them.  If you have 5 sub classes, and only
3 of them need the validations or callbacks, set it up in a special
mixin:

module PickyCallbacks
  def self.included(base)
    base.after_save :foo
    base.validates_format_of :email, :with => /.../
  end
end

--
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
This topic is locked and can not be replied to.