Jack Owels
Jack Owels

Reputation: 179

Sequel validations in concerns

I have a Sequel model like this:

class User < Sequel::Model
  include Notificatable

  def validate
    super
    validates_presence [:email]
  end
end

# concerns/notificatable.rb
module Notificatable
    extend ActiveSupport::Concern

    included do
      def validate
        super
        validates_presence [:phone]
      end
    end
end

And here I got a problem: Notificatable validate method overrides the same method in the User model. So there is no :name validations.

How can I fix it? Thanks!

Upvotes: 0

Views: 313

Answers (1)

Jeremy Evans
Jeremy Evans

Reputation: 12159

Why use a concern? Simple ruby module inclusion works for what you want:

class User < Sequel::Model
  include Notificatable

  def validate
    super
    validates_presence [:email]
  end
end

# concerns/notificatable.rb
module Notificatable
  def validate
    super
    validates_presence [:phone]
  end
end

Upvotes: 1

Related Questions