« back

Rails, SearchKick and ActAsTaggableOn

If you are using SearchKick with ActAsTaggableOn, you may have hit some issues updating a single entity after adding a tag.

To make it works, you have to extend the Tagging class (inside the ActsAsTaggableOne module) by adding an after_save method.

Solution: Monkey patch Tagging class like this (I have created a config/initializers/act_as_taggable.rb initializer file).

module ActsAsTaggableOn
  class Tagging < ::ActiveRecord::Base
    after_save :reindex

    def reindex
      taggable.reload.reindex
    end
  end
end

Note: Do not use after_commit, as its only triggered on the "parent" class.

Thanks to Andrew Kane for helping me on this.