```ruby
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
```

Use table_name in tags where clause
user
```ruby
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
```
assistant