Rails 4 + Rakismet + Akismet无法正常工作

Rails 4

我的application.rb:

require File.expand_path('../boot', __FILE__) require 'rails/all' Bundler.require(*Rails.groups) module Helpdesk class Application < Rails::Application config.rakismet.key = '3sf1b9e19da3' config.rakismet.url = 'http://127.0.0.1:3000/' end end 

我的模特:

 class Ticket < ActiveRecord::Base include Rakismet::Model has_many :pictures, as: :imageable belongs_to :status belongs_to :stuff belongs_to :department validates :customer_name, :customer_email, :subject, :body, presence: true def init_sp(permalink, request) self.permalink = permalink self.remote_ip = request.remote_ip self.user_agent = request.env["HTTP_USER_AGENT"], self.referrer = request.env["HTTP_REFERER"] end rakismet_attrs author: :customer_name, author_url: :permalink, author_email: :customer_email, content: :body, permalink: :permalink, user_ip: :remote_ip, user_agent: :user_agent, referrer: :referrer end 

我的控制器:

 class TicketsController < ApplicationController def new @ticket = Ticket.new end def create @ticket = Ticket.new(ticket_params) @ticket.init_sp(ticket_show_path(Ticket.generate_id), request) t = Logger.new(STDOUT) t.debug "================================" t.debug @ticket t.debug @ticket.spam? t.debug @ticket.akismet_response t.debug "================================" if @ticket.save flash[:notice] = "Ticket created successfully. Message sent." redirect_to ticket_show_path(@ticket.token) else render "new" end end 

我的日志:

 # D, [2014-06-14T09:45:59.484731 #7688] DEBUG -- : nil D, [2014-06-14T09:45:59.485731 #7688] DEBUG -- : false 

即t.debug @ ticket.spam? 返回nil,t.debug @ ticket.akismet_response返回false

有任何想法吗?

哦,伙计:我试图帮助一些人修复他的代码,这不是一个如何使用rakismet的例子。 你应该检查rakismet文档 。

  • Imho整个init_sp都不需要。 正如另一个答案中提到的:如果你打电话给.spam? 从控制器,它将有权访问该request
  • 我不会使author_url =永久链接,它应该是一个url进入作者(票证),这可能表明作者是垃圾邮件发送者。 你可以把它留空。
  • 你为什么不使用Rails.logger.debug
  • 您是否注意到您刚刚与世界分享了您的akismet密钥?

但除此之外, .spam? 返回nil ,来源似乎不可能。 然而, akismet_response可能是false 。 所以afaik akismet不认为它是垃圾邮件。

从rakismet文档:

触发积极垃圾邮件响应的唯一保证方法是将评论作者设置为“viagra-test-123”。

Interesting Posts