acts_as_taggable tag cloud modification (postgres fix)
Published: March 3rd, 2007There’s a problem with acts_as_taggable if you use postgres, here’s the fix!
While developing a new project I was given, I obviously wanted to play around with tags. So I went with the acts_as_taggable plugin by DHH, even though it doesn’t have the most features (compared to acts_as_taggable_on_steroids), it will do enough.
After getting it all set up and making some customizations, I was kind of shocked that there wasn’t a tag cloud method for the plugin. Luckily the community has already found ways to do it, and that’s great.
All was well in the code except I noticed I was getting sql query errors. It was rather self imformitative “Must include so and so in group by section” but if other people are having trouble, go ahead and try the following code in tag.rb (after following Juxie’s tutorial)
def self.tags(options = {}) query = "select tags.id, name, count(*) as count" query << " from taggings, tags" query << " where tags.id = tag_id" query << " group by tag_id, tags.id, tags.name" query << " order by #{options[:order]}" if options[:order] != nil query << " limit #{options[:limit]}" if options[:limit] != nil tags = Tag.find_by_sql(query) end

Ready. Set. Go.
In terms of the formatting, you're allowed to use markdown, textile, or basic html; it's truly up to you -- what strikes your fancy?
You don't have to worry about your e-mail address being sold to a russian-spam-mafia. I'm only going to use it for my own weird needs; like asking you out for a date on a lonely night of coding.