Douglas Shearer
2006-Oct-05 19:18 UTC
counter_cache with conditions? [Store non-spam comments #]
Hi guys. Ok, I have a post model, and a comments model (Very similar to the migrations screencast on the RoR website). I use a counter cache to store the number of comments each post has with the post record. I have just added Akismet anti-spam to my blog app, and am storing the spam comments in the database until I have a change to manually verify their spam-worthiness. The spam and non-spam comments are differentiated by a boolean column called is_spam. Thus I now want my counter_cache in the post model to only count those comments that are NOT marked as spam (When a user clicks on a link that says ''5 comments'' only to discover there are none because they are all spams, they are going to be slightly confused. Any way I can achieve this? Dougal - 3 weeks on Rails. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Douglas Shearer
2006-Oct-06 20:10 UTC
Re: counter_cache with conditions? [Store non-spam comments
Douglas Shearer wrote:> Any way I can achieve this?Not really one to wait around I came up with my own solution using a separate column in the posts table, and after_save and after_destroy methods to update this in my comment model. I made a post at my blog: http://douglasfshearer.dyndns.org/blog/custom-counter_cache-with-conditions Thanks. Dougal. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---