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 -- Posted via http://www.ruby-forum.com/.
On 3/19/06, Alex <maccman@gmail.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsIn 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060319/91b97dc4/attachment.html
I''ve posted a ruby-sample-code for tagclouds on my blog, a while ago
tijer wrote:> I''ve posted a ruby-sample-code for tagclouds on my blog, a while agoWhat''s the address? -- Posted via http://www.ruby-forum.com/.
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?-- Posted via http://www.ruby-forum.com/.
I''m sorry about that. I was using the freeonrails.com interface and I didn''t keep in mind that you guys wouldn''t be able to see the a html tag. Here''s the link: http://troelsbay.dk/blog/2006-02-12/Ruby+tag+cloud
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 -- Posted via http://www.ruby-forum.com/.
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%. On 3/19/06, Alex <maccman@gmail.com> wrote:> 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >