Search code examples
ruby-on-railsrubyvalidation

skip validation in parent class


I have a few classes deriving from A. A does some validation In the specific case of class B that inherits from A, I'd like to skip the validation.

I'm using active interaction btw

class A < ActiveInteraction::Base
  string :s

  validate :valid
        
  private

  def valid
    #raise something unless s equals "banana"
  end
end


class B < A 
  #do something here to skip A's validation??          
  def execute
    #super cool logic
  end
end

Solution

  • Since this is a subclass, you can override the valid method to do something else, or even nothing:

    class B < A       
      def execute
        #super cool logic
      end
    
      private
    
      def valid
        # Do nothing
      end
    end