Read more

ActsAsTaggableOn: Cache tag lists

Tobias Kraze
November 25, 2011Software engineer at makandra GmbH

For performance improvements (and to remove the need for eager loading), the ActsAsTaggableOn gem Show archive.org snapshot supports caching your tag lists directly in your model. To enable this, simply add a cached_tag_list column to your table.

Example:

class Company < ActiveRecord::Base
  acts_as_taggable_on :categories
end
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

The cache column has to be named cached_category_list.

Existing data

If you already have existing data, you have to save all records with tags once, after you've added the column, like this:

Company.all.each do |company|
  company.category_list # it seems you need to do this first to generate the list
  company.save!
end
Posted by Tobias Kraze to makandra dev (2011-11-25 10:29)