Ruby on rails 轨道4+;Rakismet+;Akismet工作不正常
轨道4 My application.rb:Ruby on rails 轨道4+;Rakismet+;Akismet工作不正常,ruby-on-rails,ruby,akismet,Ruby On Rails,Ruby,Akismet,轨道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 = 'h
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
需要文件。展开路径('../boot',文件)
需要“rails/all”
Bundler.require(*Rails.groups)
模块帮助台
类应用程序
我的模型:
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
classticket
我的控制器:
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
class ticketcontroller
我的日志:
#<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
#
D、 [2014-06-14T09:45:59.484731#7688]调试--:无
D、 [2014-06-14T09:45:59.485731#7688]调试--:错误
即t.debug@ticket.spam?返回nil,t.debug@ticket.akismet_响应返回false
有什么想法吗?哦,伙计:我试着帮助某个人修复他的代码,但这并不是如何使用rakismet的一个例子。你应该检查一下房间
- 我不需要整个
东西。如另一个答案中所述:如果您从控制器调用init\u sp
,它将可以访问.spam?
李>请求
- 我不会让author\u url=permalink,它应该是一个由作者(票据的作者)输入的url,这可能表明作者是垃圾邮件发送者。你可以把它留空李>
- 为什么不使用
李>Rails.logger.debug
- 你有没有注意到你刚刚和全世界分享了你的akismet钥匙李>
.spam?
返回nil
,这从源头上看似乎是不可能的,这有点奇怪。然而,akismet\u响应
很可能是false
。所以afaik akismet不认为这是垃圾邮件
从rakismet文档中:
触发正面垃圾邮件响应的唯一保证方法是将评论作者设置为“伟哥-test-123”
谢谢你的回复。我的实现有问题。把“伟哥-test-123”放进去,我还能得到span吗nil和akismet_response=false。您有哪个版本的gem?