back to home

mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.

4,993 stars
1,195 forks
307 issues
Ruby

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing mbleigh/acts-as-taggable-on in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/mbleigh/acts-as-taggable-on)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

**Table of Contents** *generated with DocToc* • ActsAsTaggableOn • Installation • Post Installation • For MySql users • Usage • Finding most or least used tags • Finding Tagged Objects • Relationships • Dynamic Tag Contexts • Tag Parsers • Tag Ownership • Working with Owned Tags • Adding owned tags • Removing owned tags • Dirty objects • Tag cloud calculations • Configuration • Upgrading • Contributors • Compatibility • Testing • License ActsAsTaggableOn This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney. It has evolved substantially since that point, but all credit goes to him for the initial tagging functionality that so many people have used. For instance, in a social network, a user might have tags that are called skills, interests, sports, and more. There is no real way to differentiate between tags and so an implementation of this type is not possible with acts as taggable on steroids. Enter Acts as Taggable On. Rather than tying functionality to a specific keyword (namely ), acts as taggable on allows you to specify an arbitrary number of tag "contexts" that can be used locally or in combination in the same way steroids was used. Installation To use it, add it to your Gemfile: and bundle: Post Installation Install migrations Review the generated migrations then migrate : If you do not wish or need to support multi-tenancy, the migration for is optional and can be discarded safely. For MySql users You can circumvent at any time the problem of special characters issue 623 by setting in an initializer file: Or by running this rake task: See the Configuration section for more details, and a general note valid for older version of the gem. Usage Setup Add and remove a single tag Add and remove multiple tags in an array You can also add and remove tags in format of String. This would be convenient in some cases such as handling tag input param in a String. Pay attention you need to add as option in this case. You may also want to take a look at delimiter in the string. The default is comma so you don't need to do anything here. However, if you made a change on delimiter setting, make sure the string will match. See configuration for more about delimiter. You can also add and remove tags by direct assignment. Note this will remove existing tags so use it with attention. With the defined context in model, you have multiple new methods at disposal to manage and view the tags in the context. For example, with context these methods are added to the model: (and , ), (plural), . To preserve the order in which tags are created use : Finding most or least used tags You can find the most or least used tags by using: You can also filter the results by passing the method a limit, however the default limit is 20. Finding Tagged Objects Acts As Taggable On uses scopes to create an association for tags. This way you can mix and match to filter down your results. Wildcard tag search You now have the following options for prefix, suffix and containment search, along with or option. Use to place a wildcard at the end of the tag. It will be looking for and in SQL. Use to place a wildcard at the beginning of the tag. It will be looking for and in SQL. Use to place a wildcard both at the beginning and the end of the tag. It will be looking for and in SQL. __Tip:__ or will return , an empty set of records. Relationships You can find objects of the same type based on similar tags on certain contexts. Also, objects will be returned in descending order based on the total number of matched tags. Dynamic Tag Contexts In addition to the generated tag contexts in the definition, it is also possible to allow for dynamic tag contexts (this could be user generated tag contexts!) Finding tags based on context You can find tags for a specific context by using the scope: Tag Parsers If you want to change how tags are parsed, you can define your own implementation: Now you can use this parser, passing it as parameter: Or change it globally: Tag Ownership Tags can have owners: Working with Owned Tags Note that only returns tags whose taggings do not have an owner. Continuing from the above example: To retrieve all tags of an object (regardless of ownership) or if only one owner can tag the object, use . Adding owned tags Note that **owned tags** are added all at once, in the form of ***comma separated tags*** in string. Also, when you try to add **owned tags** again, it simply overwrites the previous set of **owned tags**. So to append tags in previously existing **owned tags** list, go as follows: Removing owned tags Similarly as above, removing will be as follows: Tag Tenancy Tags support multi-tenancy. This is useful for applications where a Tag belongs to a scoped set of models: Dirty objects Tag cloud calculations To construct tag clouds, the frequency of each tag needs to be calculated. Because we specified on the class, we can get a calculation of all the tag counts by using . But what if we wanted a tag count for a single user's posts? To achieve this we call tag_counts on the association: A helper is included to assist with generating tag clouds. Here is an example that generates a tag cloud. Helper: Controller: View: CSS: Configuration If you would like to remove unused tag objects after removing taggings, add: If you want force tags to be saved downcased: If you want tags to be saved parametrized (you can redefine to_param as well): If you would like tags to be case-sensitive and not use LIKE queries for creation: If you would like to have an exact match covering special characters with MySql: If you would like to specify table names: If you want to change the default delimiter (it defaults to ','). You can also pass in an array of delimiters such as ([',', '|']): *NOTE 1: SQLite by default can't upcase or downcase multibyte characters, resulting in unwanted behavior. Load the SQLite ICU extension for proper handl…