0

Rails 4

My 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

My model:

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

My controller:

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

My Log:

#<Ticket id: 5, status_id: 1, customer_name: "Drobazko", customer_email: "drobazko@gmail.com", token: "QOI-017-QIT-078-ULR", body: "Viagra", subject: "Subj", created_at: "2014-06-14 06:45:58"
, updated_at: "2014-06-14 06:45:58", stuff_id: nil, department_id: nil, permalink: "/tickets/XQT-689-KZR-289-USQ", remote_ip: "127.0.0.1", user_agent: ["Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36", "http://127.0.0.1:3000/tickets/new"], referrer: "http://127.0.0.1:3000/tickets/new">
D, [2014-06-14T09:45:59.484731 #7688] DEBUG -- : nil
D, [2014-06-14T09:45:59.485731 #7688] DEBUG -- : false

I.e. t.debug @ticket.spam? returns nil, t.debug @ticket.akismet_response returns false

Any ideas?

4

1 回答 1

1

哦,伙计:我试图帮助某个人修复他的代码,但这并不是如何使用 rakismet 的示例。您应该检查rakismet 文档

  • 恕我直言,不需要整件事init_sp。如另一个答案中所述:如果您.spam?从控制器调用,它将可以访问request.
  • 我不会设置 author_url=permalink,它应该是一个输入作者(票证)的 url,这可能表明作者是垃圾邮件发送者。你可以把它留空。
  • 你为什么不使用Rails.logger.debug?
  • 您是否注意到您刚刚与全世界分享了您的 akismet 密钥?

但除此之外,.spam?return有点奇怪nil,从源头上看似乎是不可能的。但是很akismet_response可能是false。所以 afaik akismet 只是不认为它是垃圾邮件。

从 rakismet 文档中:

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

于 2014-06-14T17:14:26.273 回答