module HasTags
  extend ActiveSupport::Concern

  included do
    scope :with_tag, -> (key) { where("tags ? '#{key}'") }
    scope :with_tag_equals, -> (key, value) { where("tags -> '#{key}' = '#{value}'") }
  end
end

module HasTags
  extend ActiveSupport::Concern

  included do
    scope :with_tag, -> (key) { where("#{self.table_name}.tags ? '#{key}'") }
    scope :with_tag_equals, -> (key, value) { where("#{self.table_name}.tags -> '#{key}' = '#{value}'") }
  end
end

Use table_name in tags where clause
Use table_name in tags where clause
