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.
53a1f0aba6f0489d49f5e6fc3df323fa?d=identicon&s=25 Robert James (robertjames)
on 2007-04-30 22: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?
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-04-30 23:23
(Received via mailing list)
On 4/30/07, S. Robert James <srobertjames@gmail.com> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
This topic is locked and can not be replied to.