Acts As Taggable on Steroids
Posted by BM5k on March 15, 2008 at 03:02 AM
Most of this was stolen directly from the Readme
Since I stole everything else, I figured I’d duplicate the donation link as well.
If you find this plugin useful, please consider a donation to the author to show your support!
Author’s Email: jonathan.viney@gmail.com
Installation
ruby script/plugin install
http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids
ruby script/generate acts_as_taggable_migration
rake db:migrate
Tag Cloud
A helper is included to assist with generating tag clouds. Include it in your helper file:module ApplicationHelper
include TagsHelper
end
Here is an example that generates a tag cloud.
Controllerclass PostController < ApplicationControllerView
def tag_cloud
@tags = Post.tag_counts
end
end
<% tag_cloud @tags, %w(css1 css2 css3 css4) do |tag, css_class| %>
<%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
<% end %>
Caching
It is useful to cache the list of tags to reduce the number of queries executed. To do this, add a column named cached_tag_list to the model which is being tagged. The column should be long enough to hold the full tag list and must have a default value of null, not an empty string.
Call save_cached_tag_list manually to update the cache!
h3. environment.rb
TagList.delimiter = " " # use spaces instead of commas
Tag.destroy_unused = true # automatically remove dead tags
Comments
There are 0 comments on this post. Post yours →
Post a comment
Required fields in bold.