github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

rsl / acts_as_snook

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 113
    • 2
  • Source
  • Commits
  • Network (2)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

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! — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

added custom rule functionality 
rsl (author)
Mon Jun 22 06:34:53 -0700 2009
commit  4b121dde11fbd7526d1696ee0eceb9d93020cc99
tree    8d9ce45784bfa9102fb0688d13ff2e4f730378e9
parent  52b9e8b98dfb1cd51dd5213fd20016027d90a0ed
acts_as_snook /
name age
history
message
file .gitignore Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
file CHANGELOG Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
file MIT-LICENSE Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
file README.rdoc Sun May 17 06:45:52 -0700 2009 updated to not decrement ham count when moving ... [rsl]
file Rakefile Tue Sep 23 08:51:58 -0700 2008 fixed bad reference to README.rdoc [rsl]
file init.rb Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
directory lib/ Mon Jun 22 06:34:53 -0700 2009 added custom rule functionality [rsl]
directory tasks/ Sat Apr 05 12:34:03 -0700 2008 initial commit [rsl]
directory test/ Mon Jun 22 06:34:53 -0700 2009 added custom rule functionality [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.

ActsAsSnook can also be configured to maintain a counter cache of ham comments [ham being the opposite of spam] for you. If your comment model has only one belongs_to association, this functionality will be automatically added. If not, you can add it in by manually configuring the following options:

  • :comment_belongs_to - The name of the parent class that comments belong to.
  • :ham_comments_count_field - The name of the attribute on the parent class which maintains the counter cache.

Note: Do not rely on an association setup like belongs_to :entry, :counter_cache => true for displaying comment count. The number returned there is the number of total comments, irrespective of spam status.

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"})

If you have provided a ham_comments_count attribute on your comment’s parent class (in this case, Entry) you also get Entry#ham_comments_count. See the documentation for the acts_as_snook method for more information on that.

Credits and Thanks

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

Thanks also to the following for their help and suggestions: Dana Jones

Copyright © 2008 Lucky Sneaks, released under the MIT license

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server