Topic: Akismet plugin not working

I'm using the akismet library for ruby to flag spam on my blog but ever since I converted the form submission into an AJAX submission the spam doesnt seem to be getting trapped. This is the code for my action.

def addcomment
      @post = Post.find_by_permalink(params[:id])
      @comments=@post.comments
      @comment=Comment.new(params[:comment])
      params[:comment].merge!({:ip=>request.remote_ip})
      unless check_comment_for_spam(@comment.name, @comment.comment)
      @comment = @post.comments.build(params[:comment])
      if @comment.save
        return if request.xhr?
        render :partial => "blogcomments"
      end
    end
# And the function for akismet is as follows;

protected
   
    def check_comment_for_spam(author, text)
      @akismet = Akismet.new('722f07e5729b', 'http://blog.somename.com') # blog url: e.g. http://sas.sparklingstudios.com
     
     # return true when API key isn't valid, YOUR FAULT!!
      return true unless @akismet.verifyAPIKey
     
     # will return false, when everthing is ok and true when Akismet thinks the comment is spam.
     return @akismet.commentCheck(
               request.remote_ip,            # remote IP
               request.user_agent,           # user agent
               request.env['HTTP_REFERER'],  # http referer
               '',                           # permalink
               'comment',                    # comment type
               author,                       # author name
               '',                           # author email
               '',                           # author url
               text,                         # comment text
               {})                           # other
             end


Any idea why it isn't working?

Re: Akismet plugin not working

Come on people!!..I'm sure somebody has had the same experience with the Akismet plugin..please help a brother out...

Re: Akismet plugin not working

The only thing I noticed is you seem to be missing an "end" at the end off addcomment, is that just how you've pasted the code? Also does the comment get submitted properly apart from spam not being caught?

Alex

P.S. Have you looked into the Askimet plugin? I think it makes for nicer code, but whether it will help your problem at all I have no idea. Still, it may be worth a try wink.

Re: Akismet plugin not working

alexpt wrote:

The only thing I noticed is you seem to be missing an "end" at the end off addcomment, is that just how you've pasted the code? Also does the comment get submitted properly apart from spam not being caught?

Alex

P.S. Have you looked into the Askimet plugin? I think it makes for nicer code, but whether it will help your problem at all I have no idea. Still, it may be worth a try wink.

Sorry bout that let me paste the code again:

def addcomment
      @post = Post.find_by_permalink(params[:id])
      @comments=@post.comments
      @comment=Comment.new(params[:comment])
      params[:comment].merge!({:ip=>request.remote_ip})
      unless check_comment_for_spam(@comment.name, @comment.comment)
      @comment = @post.comments.build(params[:comment])
      if @comment.save
        return if request.xhr?
        render :partial => "blogcomments"
      end
    end
end

The submission code does work very well only the anti-spam doesn't work