public
Description: A comment spam solution that doesn't rely on CAPTCHAs, Javascript, or external web services. In other words, a comment spam solution that doesn't suck!
Clone URL: git://github.com/rsl/acts_as_snook.git
Search Repo:
name age message
folder .gitignore Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
folder CHANGELOG Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
folder MIT-LICENSE Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
folder README.rdoc Sat Apr 05 12:40:41 -0700 2008 renamed readme [rsl]
folder Rakefile Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
folder init.rb Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
folder lib/ Tue Apr 15 14:14:06 -0700 2008 more tweakage [rsl]
folder tasks/ Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
folder test/ Tue May 13 17:02:31 -0700 2008 changed snook calculation to only on create [rsl]
README.rdoc

ActsAsSnook

ActsAsSnook is a simple and elegant method of handling comment spam that doesn’t rely on CAPTCHAS or Javascript or external web services. It uses a point based system to detect common traits of comment spam. The details of this implementation can be found in the source code and tests as well as the original blog post I based this plugin on (see "Thanks and credits").

Setup

ActsAsSnook assumes that you have the following fields on your comment model: author [string], email [string], url [string], body [text], and spam_status [string]. The name of these attributes can be changed as shown in the next section.

Usage

  acts_as_snook

That’s it if you want to use the default attributes I mentioned above. If you need to customize them, just specify them as arguments to acts_as_snook:

  acts_as_snook :author_field => :user, :body_field => :comment # Etc, etc

You may also add your own keywords to the list of spam keywords that ActsAsSnook uses to detect spam by adding them to the arguments:

  acts_as_snook :spam_words => %{hatespeech ignorantlanguage blathering}

ActsAsSnook also provides some helper methods for determining the spam status of a comment.

comment.ham?:Returns true for comments not marked as spam. "Ham" comments are safe for displaying on your site as is. This is the method you should most likely be using to check an individual comment.
comment.spam?:Returns true for comments marked as spam. These are should not be shown on your site.
comment.moderate?:Returns true for comments that were not marked as actual spam but did not get enough points to be marked as "ham" either. The spam_status field for these will contain "moderate".
Comment#ham:Shortcut for Comment#find(:all, :conditions => {:spam_status => "ham"})
Comment#spam:Shortcut for Comment#find(:all, :conditions => {:spam_status => "spam"})
Comment#moderate:Shortcut for Comment#find(:all, :conditions => {:spam_status => "moderate"})

Credits and Thanks

Much love to Jonathan Snook, web developer extraordinaire. Most of the algorithms of ActsAsSnook [as well as the name, obviously] come from his blog post which you can find here[http://snook.ca/archives/other/effective_blog_comment_spam_blocker] The actual implementation I myself wrote.

Copyright © 2008 Lucky Sneaks, released under the MIT license