Helper for generating Technorati tags
Need to support Technorati tags in your application?
Here's a helper that does all the work. Just give it a list of tags and the helper will spit out all the necessary html for Technorati to index your content. (When you deploy, don't forget to ping them so they index you.)
def technorati_tags_for(model)
tag_links = Array.new
model.tags.split(',').sort.each do |tag|
tag_links << '<a href="http://technorati.com/tag/' +
tag.split(" ").join("+") + '" rel="tag">' +
tag + '</a>'
end
tag_links.join("\n")
end
Assumptions
Your tags are comma delimited and stored in a model attribute called tags. (This helper should be placed on each individual blog post... typically the "show" action.)
Extra credit
- If you have a tag cloud, replace
http://technorati.com/tag/with the path to your local tag pages. - Don't need to show the tags? Wrap them in a div that's styled with
display: none;. - Think about automatically adding a default set of tags to each post. If, for instance your blog was 100% about Rails, add tags for "rails" and "ruby on rails". You can add these in the helper without cluttering up your database or admin interface with redundant information.
September 28, 2007

Or:
call like:
Much nicer, Paul.
Your code probably works a lot better for people for using the various tag plugins. In my case, I'm solely adding tags for the purpose of supporting Technorati on a simple blog, so that's why I'm fetching tags directly from the model.
New comments are disabled right now. Once we finish migrating this blog, we'll restore them.