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
On 3/19/06, Alex [email protected] wrote:
Rails mailing list
[email protected]
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
I’ve posted a ruby-sample-code for tagclouds on my blog, a while ago
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?
Would be interested to know what the database structure is for a tag
cloud? I saw this post:
but apparently there may be a different recommended path with RoR? Any
insights?
VW
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%.
tijer wrote:
I’ve posted a ruby-sample-code for tagclouds on my blog, a while ago
What’s the address?