Forum: Ruby on Rails Tag Cloud Code

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Baf018e2cc4616e4776d323215c7136c?d=identicon&s=25 Alex (Guest)
on 2006-03-19 13:58
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
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 Joey (Guest)
on 2006-03-19 14:13
(Received via mailing list)
On 3/19/06, Alex <maccman@gmail.com> wrote:
> Rails mailing list
> Rails@lists.rubyonrails.org
> 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
57c47cc8bb68ed845e312aca48296405?d=identicon&s=25 tijer (Guest)
on 2006-03-19 14:28
(Received via mailing list)
I've posted a ruby-sample-code for tagclouds on my blog, a while ago
Baf018e2cc4616e4776d323215c7136c?d=identicon&s=25 Alex (Guest)
on 2006-03-19 14:38
tijer wrote:
> I've posted a ruby-sample-code for tagclouds on my blog, a while ago

What's the address?
0895305feb2b97049c39b08972233d02?d=identicon&s=25 Anthony Rudgick (Guest)
on 2006-03-19 17:12
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?
26ca684555abbdb44f01bd1e165e649b?d=identicon&s=25 vincew (Guest)
on 2006-03-20 06:45
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-data...

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

VW
5b1b906e6d15f3c7b211dac6242e490b?d=identicon&s=25 albert elegance (Guest)
on 2006-03-20 07:47
(Received via mailing list)
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%.
This topic is locked and can not be replied to.