• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated over 15 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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!

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