在我的模型中,我有:
class ArticleComment < ActiveRecord::Base
include Rakismet::Model
validates :text, :presence => true
belongs_to :article
belongs_to :user
comment, permalink, request, username, email, text, remote_ip,
user_agent, referrer = nil
def init_sp(comment_, permalink_, request_, username_, email_, text_)
comment, permalink, request, username, email, text =
comment_, permalink_, request_, username, email_, text_
remote_ip = request_.remote_ip
user_agent = request_.env["HTTP_USER_AGENT"],
referrer = request_.env["HTTP_REFERER"]
end
rakismet_attrs author: username, author_url: permalink, author_email: email,
content: text, permalink: permalink, user_ip: remote_ip,
user_agent: user_agent, referrer: referrer
binding.pry
end
在控制器中:
def create
@article_comment = ArticleComment.new(article_comment_params)
@spam = @article_comment.init_sp(@article_comment, params[:permalink],
request, username, email, article_comment_params[:text])
if !@article_comment.spam?
....
所以我需要在控制器中设置字段 like ip
, user_agent
,text
我该怎么做?
现在我看到我的价值为零(为什么?
如何在控制器的帮助下设置 rakismet_attrs 值?