There´s already a new version of the acts_as_taggable mixin available and look what it is capable of now: # Gets the top 10 tags for all photos Photo.tags_count :limit => 10 # => { ''beer'' => 68, ''wine'' => 37, ''vodka'' => ''22'', ... } # Gets the tags count that are greater than 30 Photo.tags_count :count => ''> 30'' # => { ''beer'' => 68, ''wine'' => 37 } More about it here: http://dema.ruby.com.br/articles/2005/09/06/tag-counting-anyone I promise this is the last release of the week. ;-) Cheers, Demetrius -- http://dema.ruby.com.br - Rails from a .NET perspective
Steve Meyfroidt
2005-Sep-06 16:58 UTC
RE: [ANN] acts_as_taggable v4 - Tag Counting Anyone?
The next release for this week could include "related tags" maybe? I implemented this by looking for items tagged with multiple tags that include the tag in question: the union of all those tags are ''related'' to the first.> -----Original Message----- > From: Demetrius Nunes [mailto:demetrius-fDpYTK8McCzCdMRJFJuMdgh0onu2mTI+@public.gmane.org] > Sent: 06 September 2005 16:25 > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails] [ANN] acts_as_taggable v4 - Tag Counting Anyone? > > There´s already a new version of the acts_as_taggable mixin available > and look what it is capable of now: > > # Gets the top 10 tags for all photos > Photo.tags_count :limit => 10 # => { ''beer'' => 68, ''wine'' => 37, ''vodka'' > => ''22'', ... } > > # Gets the tags count that are greater than 30 > Photo.tags_count :count => ''> 30'' # => { ''beer'' => 68, ''wine'' => 37 } > > More about it here: > http://dema.ruby.com.br/articles/2005/09/06/tag-counting-anyone > > I promise this is the last release of the week. ;-) > > Cheers, > Demetrius > -- > http://dema.ruby.com.br - Rails from a .NET perspective > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Demetrius Nunes
2005-Sep-06 17:06 UTC
Re: [ANN] acts_as_taggable v4 - Tag Counting Anyone?
Steve Meyfroidt wrote:> The next release for this week could include "related tags" maybe? > > I implemented this by looking for items tagged with multiple tags that > include the tag in question: the union of all those tags are ''related'' > to the first.Yes, that´s planned to be implemented already. But I think it won´t be done till next week or the end of this week. But, if you´d like, you can implement it yourself and send me a patch with proper documentation and tests and I´ll try to integrate it. Thanks Dema -- http://dema.ruby.com.br - Rails from a .NET perspective
Demetrius great work, thanks! The more releases the merrier, don''t let us slow you down ;) -San P.S. Perhaps add an alias ''tag_count'' instead of ''tags_count'' (more natural expression in English I believe - reads like ''count per tag'') Demetrius Nunes wrote:> There´s already a new version of the acts_as_taggable mixin available > and look what it is capable of now: > > # Gets the top 10 tags for all photos > Photo.tags_count :limit => 10 # => { ''beer'' => 68, ''wine'' => 37, ''vodka'' > => ''22'', ... } > > # Gets the tags count that are greater than 30 > Photo.tags_count :count => ''> 30'' # => { ''beer'' => 68, ''wine'' => 37 } > > More about it here: > http://dema.ruby.com.br/articles/2005/09/06/tag-counting-anyone > > I promise this is the last release of the week. ;-) > > Cheers, > Demetrius
Demetrius Nunes
2005-Sep-06 21:30 UTC
Re: [ANN] acts_as_taggable v4 - Tag Counting Anyone?
San wrote:> > Demetrius great work, thanks! The more releases the merrier, don''t let > us slow you down ;) > > -San > > P.S. Perhaps add an alias ''tag_count'' instead of ''tags_count'' (more > natural expression in English I believe - reads like ''count per tag'') >Thanks San, Thanks to instant user feedback I´ve already released a couple of bugfix versions just this afternoon. And thanks for the suggestion on the ''tag_count'' spelling. I will add the alias for the next version for sure. rgds Demetrius -- http://dema.ruby.com.br - Rails from a .NET perspective
> Thanks to instant user feedback I´ve already released a couple of bugfix > versions just this afternoon. > > And thanks for the suggestion on the ''tag_count'' spelling. I will add > the alias for the next version for sure. > > rgds > DemetriusAlright enough playing, get a subversion repository of this bad boy :) It would be nice to just ''svn up'' your rapid updates...... -- rick http://techno-weenie.net
Hi Demetrius, Great work on acts_as_taggable.. I have one suggestion which relates to method scope: In the Taggable module, you define three class methods: acts_as_taggable, find_tagged_with, and tags_count. All three functions are added to ActiveRecord::Base. This makes sense for acts_as_taggable because you need its scope to be ActiveRecord::Base so that it can be placed in the class as simple function call. However, it is my opinion that find_tagged_with and tags_count should *not* be scoped to ActiveRecord::Base because that makes the methods available to all ActiveRecord::Base subclasses no matter if they invoked acts_as_taggable or not. If I do this test on any model: model.respond_to? tags_count, I''ll get true as the result, which feels wrong. If you agree with me, then this can be easily remedied by changing ''def find_tagged_with'' and ''def tags_count'' with ''def self.find_tagged_with'' and ''def self.tags_count''. Once this is done, only the classes which have invoked ''acts_as_taggable'' in their class definition will respond to those methods (you''ll need to run your unit tests to check for side effects if you decide to make the change, of course). I hope this is helpful. Scott On 9/6/05, Demetrius Nunes <demetrius-fDpYTK8McCzCdMRJFJuMdgh0onu2mTI+@public.gmane.org> wrote:> > There´s already a new version of the acts_as_taggable mixin available > and look what it is capable of now: > > # Gets the top 10 tags for all photos > Photo.tags_count :limit => 10 # => { ''beer'' => 68, ''wine'' => 37, ''vodka'' > => ''22'', ... } > > # Gets the tags count that are greater than 30 > Photo.tags_count :count => ''> 30'' # => { ''beer'' => 68, ''wine'' => 37 } > > More about it here: > http://dema.ruby.com.br/articles/2005/09/06/tag-counting-anyone > > I promise this is the last release of the week. ;-) > > Cheers, > Demetrius > -- > http://dema.ruby.com.br - Rails from a .NET perspective > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Steve Meyfroidt
2005-Sep-07 11:13 UTC
RE: Re: [ANN] acts_as_taggable v4 - Tag Counting Anyone?
If I beat you to doing that I''ll send it through. (I''m still using my own "taggable" code at the moment).> -----Original Message----- > From: Demetrius Nunes [mailto:demetrius-fDpYTK8McCzCdMRJFJuMdgh0onu2mTI+@public.gmane.org] > Sent: 06 September 2005 18:07 > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails] Re: [ANN] acts_as_taggable v4 - Tag Counting Anyone? > > Steve Meyfroidt wrote: > > The next release for this week could include "related tags" maybe? > > > > I implemented this by looking for items tagged with multiple tags that > > include the tag in question: the union of all those tags are ''related'' > > to the first. > > Yes, that´s planned to be implemented already. But I think it won´t be > done till next week or the end of this week. > > But, if you´d like, you can implement it yourself and send me a patch > with proper documentation and tests and I´ll try to integrate it. > > Thanks > Dema > -- > http://dema.ruby.com.br - Rails from a .NET perspective > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Demetrius Nunes
2005-Sep-07 16:55 UTC
Re: [ANN] acts_as_taggable v4 - Tag Counting Anyone?
scott moody wrote:> Hi Demetrius, > > Great work on acts_as_taggable.. I have one suggestion which relates to > method scope: > > In the Taggable module, you define three class methods: > acts_as_taggable, find_tagged_with, and tags_count. > All three functions are added to ActiveRecord::Base. This makes sense > for acts_as_taggable because you need its scope to be ActiveRecord::Base > so that it can be placed in the class as simple function call. > > However, it is my opinion that find_tagged_with and tags_count should > *not* be scoped to ActiveRecord::Base because that makes the methods > available to all ActiveRecord::Base subclasses no matter if they invoked > acts_as_taggable or not. If I do this test on any model: > model.respond_to? tags_count, I''ll get true as the result, which feels > wrong. > > If you agree with me, then this can be easily remedied by changing ''def > find_tagged_with'' and ''def tags_count'' with ''def self.find_tagged_with'' > and ''def self.tags_count''. Once this is done, only the classes which > have invoked ''acts_as_taggable'' in their class definition will respond > to those methods (you''ll need to run your unit tests to check for side > effects if you decide to make the change, of course). > > I hope this is helpful.Thanks Scott, you´re absolutely right, I haven´t realized this problem. I´ve already corrected and updated this method scope issue. Nevertheless, doing ''self.(...)'' was not the way to solve it. I had to do something else and you can check it out on the updated version. I also added a #tag_count alias for #tags_count as requested by San. Once again, thanks a lot. Regards, Demetrius -- http://dema.ruby.com.br - Rails from a .NET perspective
scott moody
2005-Sep-07 17:54 UTC
Re: Re: [ANN] acts_as_taggable v4 - Tag Counting Anyone?
"def self..." has worked as a way to create class methods in my act_as code, but I like your technique much better...it''s easier for an outsider to understand. Once again, great work...looking forward to more! -Scott On 9/7/05, Demetrius Nunes <demetrius-fDpYTK8McCzCdMRJFJuMdgh0onu2mTI+@public.gmane.org> wrote:> > scott moody wrote: > > Hi Demetrius, > > > > Great work on acts_as_taggable.. I have one suggestion which relates to > > method scope: > > > > In the Taggable module, you define three class methods: > > acts_as_taggable, find_tagged_with, and tags_count. > > All three functions are added to ActiveRecord::Base. This makes sense > > for acts_as_taggable because you need its scope to be ActiveRecord::Base > > so that it can be placed in the class as simple function call. > > > > However, it is my opinion that find_tagged_with and tags_count should > > *not* be scoped to ActiveRecord::Base because that makes the methods > > available to all ActiveRecord::Base subclasses no matter if they invoked > > acts_as_taggable or not. If I do this test on any model: > > model.respond_to? tags_count, I''ll get true as the result, which feels > > wrong. > > > > If you agree with me, then this can be easily remedied by changing ''def > > find_tagged_with'' and ''def tags_count'' with ''def self.find_tagged_with'' > > and ''def self.tags_count''. Once this is done, only the classes which > > have invoked ''acts_as_taggable'' in their class definition will respond > > to those methods (you''ll need to run your unit tests to check for side > > effects if you decide to make the change, of course). > > > > I hope this is helpful. > > Thanks Scott, you´re absolutely right, I haven´t realized this problem. > > I´ve already corrected and updated this method scope issue. > > Nevertheless, doing ''self.(...)'' was not the way to solve it. I had to > do something else and you can check it out on the updated version. > > I also added a #tag_count alias for #tags_count as requested by San. > > Once again, thanks a lot. > > Regards, > Demetrius > -- > http://dema.ruby.com.br - Rails from a .NET perspective > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails