Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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!

tree: dfae80e652

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 tasks
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
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 The actual implementation I myself wrote.

Copyright © 2008 Lucky Sneaks, released under the MIT license

Something went wrong with that request. Please try again.