Tag Cloud Code


#1

Does anyone have any sample code for a tag cloud.
I’ve looked at typo but they’ve just got complicated sql (which I don’t
have a clue about). All I want is to select tags and make them
bigger/smaller depending on the number of pages that are ‘tagged’ by
them. Thanks in advance


#2

On 3/19/06, Alex removed_email_address@domain.invalid wrote:

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

In the controller:
@tags = Tag.find(:all,:include => :tagged_objects)

In the view:
<% @tags.each do |t| %>
<%= link_to(tag.name,{}, {:style => “font-size: #{(
tag.tagged_objects.size+1)*10}px”}) %>
<% end %>
Or something like that.

joey__
http://www.feedreed.com


#3

I’ve posted a ruby-sample-code for tagclouds on my blog, a while ago


#4

i’ll assume he’s the author of
http://blog.craz8.com/articles/2005/10/28/

Alex wrote:

tijer wrote:

I’ve posted a ruby-sample-code for tagclouds on my blog, a while ago

What’s the address?


#5

Would be interested to know what the database structure is for a tag
cloud? I saw this post:
http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html

but apparently there may be a different recommended path with RoR? Any
insights?

VW


#6

My tags table caches the number of posts they’re associated with as a
database field, named post_count. The code I use (in a helper):

def cloud_view(tags)
html = “”
mid = tags.map {|i| i.post_count}.max / 3.0

tags.each do |tag|
size = 100 * tag.post_count / mid
size = 80 if size < 80
html << link_to(tag.name, “post/list/#{tag}”, :style =>
“font-size: #{size}%”) << " "
end

return html
end

This caps the maximum size of a tag to 300%, and the minimum to 80%.


#7

tijer wrote:

I’ve posted a ruby-sample-code for tagclouds on my blog, a while ago

What’s the address?