pat/gutentag

Switching between act-as-taggable and gutentag.

hcyildirim opened this issue · 4 comments

Hi,

I'm using act-as-taggable gem but it has many bugs and no one seems to fix it. And I'm thinking about switching the gems. But I have questions.

  1. Can I use this with searchkick

To use this gem with searchkick I need to create a model which inherits from tag. See: https://github.com/ankane/searchkick#getting-started

Act-as-taggable has something like below. How can I do that with gutentag?

class Tag < ActsAsTaggableOn::Tag
  after_save do
    # magic
  end
end
  1. Can I use active record model callbacks?

When new tags added to table I'm broadcasting to clients so their apps keeping up to date. Actually this is same with question 1.

  1. Can I use this with paranoia

Users can delete their account and it means their posts and post tags also be deleted. But I want to keep tags. How can I do that?

pat commented

With regards to questions 1 & 2:

You can definitely create a subclass of Gutentag::Tag (much like your example with ActsAsTaggableOn::Tag), but I'm not sure this will get you the behaviour you want. If you're manipulating the tags yourself, then you can make sure you use your tag model, but anything that deals with Gutentag internals will use Gutentag::Tag. And while it'll work from Gutentag's perspective, it'll not invoke the custom code you put in your subclass.

A better way may be to extend the original model instead, having something like this in an initialiser:

# config/initializers/gutentag.rb
Gutentag::Tag.searchkick

Gutentag::Tag.after_save do |instance|
  #
end

As for your third question: orphaned tags themselves are not deleted unless you want them to be (using Gutentag::RemoveUnused.call). If the tagged data (in your case, posts) are kept, then their tag associations will also be persisted.

Hopefully this clears things up, but feel free to ask more questions :)

Hi, thank you for response.

Im not changing gutentag original model or adding any kind of custom methods. I just want to use searchkick and callbacks. So you are saying if I create something like this, it will work?

class Tag < Gutentag::Tag
  searchkick

  after_save do
    # broadcast to clients
  end
end
pat commented

I think you should change the Gutentag::Tag model.

You can create a subclass, and if you use that model for searching and/or indexing, yes, it'll likely work. However, all of the operations within Gutentag will use the original Gutentag::Tag model instead, so you won't be able to rely on the callbacks being invoked.

Thank you!