{"id":20061670,"url":"https://github.com/tylerrick/acts_as_taggable","last_synced_at":"2025-08-05T22:09:10.240Z","repository":{"id":454369,"uuid":"77917","full_name":"TylerRick/acts_as_taggable","owner":"TylerRick","description":"git-svn clone http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids in 'upstream' branch; my changes in 'master'","archived":false,"fork":false,"pushed_at":"2008-12-02T18:20:00.000Z","size":178,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-04-11T10:51:25.991Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TylerRick.png","metadata":{"files":{"readme":"README","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2008-11-19T00:02:36.000Z","updated_at":"2021-09-11T18:32:15.000Z","dependencies_parsed_at":"2022-07-07T23:19:30.954Z","dependency_job_id":null,"html_url":"https://github.com/TylerRick/acts_as_taggable","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Facts_as_taggable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Facts_as_taggable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Facts_as_taggable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Facts_as_taggable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TylerRick","download_url":"https://codeload.github.com/TylerRick/acts_as_taggable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224454258,"owners_count":17313916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:21:27.615Z","updated_at":"2024-11-13T13:21:28.314Z","avatar_url":"https://github.com/TylerRick.png","language":"Ruby","funding_links":["http://www.paypal.com/cgi-bin/webscr?cmd=_send-money"],"categories":[],"sub_categories":[],"readme":"= acts_as_taggable_on_steroids\r\n\r\nIf you find this plugin useful, please consider a donation to show your support!\r\n\r\n  http://www.paypal.com/cgi-bin/webscr?cmd=_send-money\r\n  \r\n  Email address: jonathan.viney@gmail.com\r\n  \r\n== Instructions\r\n\r\nThis plugin is based on acts_as_taggable by DHH but includes extras\r\nsuch as tests, smarter tag assignment, and tag cloud calculations.\r\n\r\n== Installation\r\n\r\n  ruby script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids\r\n\r\n== Usage\r\n\r\n=== Prepare database\r\n\r\nGenerate and apply the migration:\r\n\r\n  ruby script/generate acts_as_taggable_migration\r\n  rake db:migrate\r\n\r\n=== Basic tagging\r\n\r\nLet's suppose users have many posts and we want those posts to have tags.\r\nThe first step is to add +acts_as_taggable+ to the Post class:\r\n\r\n  class Post \u003c ActiveRecord::Base\r\n    acts_as_taggable\r\n    \r\n    belongs_to :user\r\n  end\r\n  \r\nWe can now use the tagging methods provided by acts_as_taggable, \u003ctt\u003e#tag_list\u003c/tt\u003e and \u003ctt\u003e#tag_list=\u003c/tt\u003e. Both these\r\nmethods work like regular attribute accessors.\r\n\r\n  p = Post.find(:first)\r\n  p.tag_list # []\r\n  p.tag_list = \"Funny, Silly\"\r\n  p.save\r\n  p.tag_list # [\"Funny\", \"Silly\"]\r\n  \r\nYou can also add or remove arrays of tags.\r\n\r\n  p.tag_list.add(\"Great\", \"Awful\")\r\n  p.tag_list.remove(\"Funny\")\r\n\r\n=== Finding tagged objects\r\n\r\nTo retrieve objects tagged with a certain tag, use find_tagged_with.\r\n\r\n  Post.find_tagged_with('Funny, Silly')\r\n  \r\nBy default, find_tagged_with will find objects that have any of the given tags. To\r\nfind only objects that are tagged with all the given tags, use match_all.\r\n\r\n  Post.find_tagged_with('Funny, Silly', :match_all =\u003e true)\r\n  \r\nSee \u003ctt\u003eActiveRecord::Acts::Taggable::InstanceMethods\u003c/tt\u003e for more methods and options.\r\n\r\n=== Tag cloud calculations\r\n\r\nTo construct tag clouds, the frequency of each tag needs to be calculated.\r\nBecause we specified +acts_as_taggable+ on the \u003ctt\u003ePost\u003c/tt\u003e class, we can\r\nget a calculation of all the tag counts by using \u003ctt\u003ePost.tag_counts\u003c/tt\u003e. But what if we wanted a tag count for\r\nan single user's posts? To achieve this we call tag_counts on the association:\r\n\r\n  User.find(:first).posts.tag_counts\r\n  \r\nA helper is included to assist with generating tag clouds. Include it in your helper file:\r\n\r\n  module ApplicationHelper\r\n    include TagsHelper\r\n  end\r\n  \r\nYou can also use the \u003ctt\u003ecounts\u003c/tt\u003e method on \u003ctt\u003eTag\u003c/tt\u003e to get the counts for all tags in the database.\r\n\r\n  Tag.counts\r\n\r\nHere is an example that generates a tag cloud.\r\n\r\nController:\r\n\r\n  class PostController \u003c ApplicationController\r\n    def tag_cloud\r\n      @tags = Post.tag_counts\r\n    end\r\n  end\r\n  \r\nView:\r\n  \u003c% tag_cloud @tags, %w(css1 css2 css3 css4) do |tag, css_class| %\u003e\r\n    \u003c%= link_to tag.name, { :action =\u003e :tag, :id =\u003e tag.name }, :class =\u003e css_class %\u003e\r\n  \u003c% end %\u003e\r\n  \r\nCSS:\r\n\r\n  .css1 { font-size: 1.0em; }\r\n  .css2 { font-size: 1.2em; }\r\n  .css3 { font-size: 1.4em; }\r\n  .css4 { font-size: 1.6em; }\r\n\r\n=== Caching\r\n\r\nIt is useful to cache the list of tags to reduce the number of queries executed. To do this,\r\nadd a column named \u003ctt\u003ecached_tag_list\u003c/tt\u003e to the model which is being tagged. The column should be long enough to hold\r\nthe full tag list and must have a default value of null, not an empty string.\r\n\r\n  class CachePostTagList \u003c ActiveRecord::Migration\r\n    def self.up\r\n      add_column :posts, :cached_tag_list, :string\r\n    end\r\n  end\r\n\r\n  class Post \u003c ActiveRecord::Base\r\n    acts_as_taggable\r\n    \r\n    # The caching column defaults to cached_tag_list, but can be changed:\r\n    # \r\n    # set_cached_tag_list_column_name \"my_caching_column_name\"\r\n  end\r\n\r\nThe details of the caching are handled for you. Just continue to use the tag_list accessor as you normally would.\r\nNote that the cached tag list will not be updated if you directly create Tagging objects or manually append to the\r\n\u003ctt\u003etags\u003c/tt\u003e or \u003ctt\u003etaggings\u003c/tt\u003e associations. To update the cached tag list you should call \u003ctt\u003esave_cached_tag_list\u003c/tt\u003e manually.\r\n\r\n=== Delimiter\r\n\r\nIf you want to change the delimiter used to parse and present tags, set TagList.delimiter.\r\nFor example, to use spaces instead of commas, add the following to config/environment.rb:\r\n\r\n  TagList.delimiter = \" \"\r\n\r\n=== Unused tags\r\n\r\nSet Tag.destroy_unused to remove tags when they are no longer being\r\nused to tag any objects. Defaults to false.\r\n\r\n  Tag.destroy_unused = true\r\n\r\n=== How case insensitive is it?\r\n\r\nWhen a tag is first created, will it will be saved with the exact name (including case) that is provided.\r\n\r\nAfter that, however, the tag will be searched for and compared insensitively. If you try to add the same tag but with different case, it will not\r\nchange the case; it will add it with the original case. (So make sure you enter it correctly to begin with, or provide a way to rename tags.\r\nBut be aware that renaming it for one user will rename it for all users.)\r\n\r\nirb -\u003e run.tag_list = 'l'\r\n\r\nirb -\u003e run.save_tags; run.reload.tag_list\r\n    =\u003e [\"l\"]\r\n\r\n# Case insensitive -- will detect that you've already 'L' (even though it's spelled 'l')\r\n# Once a tag is created, its case will never change simply by people adding/removing the tag with different spellings.\r\nirb -\u003e run.tag_list = 'L'\r\n\r\nirb -\u003e run.save_tags; run.reload.tag_list\r\n    =\u003e [\"l\"]\r\n\r\n# You'd have to explicitly update its name to change its case...\r\nirb -\u003e Tag.find_by_name('l').update_attribute :name, 'L'\r\n    =\u003e true\r\n\r\n# Case insensitive; can still be found with 'l'\r\nirb -\u003e Tag.find_by_name('l')\r\n    =\u003e #\u003cTag id: 6, name: \"L\"\u003e\r\n\r\n=== Contributing\r\n\r\nPull requests welcome at http://github.com/TylerRick/acts_as_taggable_on_steroids/tree/master\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Facts_as_taggable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerrick%2Facts_as_taggable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Facts_as_taggable/lists"}