The Railscasts site has been getting a lot of comment spam in the past, but no longer. In this episode I will show you how I solved this problem by using the Akismet web service.
# comments_controller.rb
def create
@comment = Comment.new(params[:comment])
@comment.request = request
if @comment.save
if @comment.approved?
flash[:notice] = "Thanks for the comment."
else
flash[:error] = "Unfortunately this comment is considered spam by Akismet. " +
"It will show up once it has been approved by the administrator."
end
redirect_to episode_path(@comment.episode_id)
else
render :action => 'new'
end
end
def destroy_multiple
Comment.destroy(params[:comment_ids])
flash[:notice] = "Successfully destroyed comments."
redirect_to comments_path
end
def approve
@comment = Comment.find(params[:id])
@comment.mark_as_ham!
redirect_to comments_path
end
def reject
@comment = Comment.find(params[:id])
@comment.mark_as_spam!
redirect_to comments_path
end
# models/comment.rb
before_create :check_for_spam
def request=(request)
self.user_ip = request.remote_ip
self.user_agent = request.env['HTTP_USER_AGENT']
self.referrer = request.env['HTTP_REFERER']
end
def check_for_spam
self.approved = !Akismetor.spam?(akismet_attributes)
true # return true so it doesn't stop save
end
def akismet_attributes
{
:key => 'abc123',
:blog => 'http://railscasts.com',
:user_ip => user_ip,
:user_agent => user_agent,
:comment_author => name,
:comment_author_email => email,
:comment_author_url => site_url,
:comment_content => content
}
end
def mark_as_spam!
update_attribute(:approved, false)
Akismetor.submit_spam(akismet_attributes)
end
def mark_as_ham!
update_attribute(:approved, true)
Akismetor.submit_ham(akismet_attributes)
end
分享到:
相关推荐
topic postings in their once-helpful newsgroups, and fear that the community of newsgroup readers will dissolve in disgust.Stopping Spam looks at the problem of spam and explains ways you can ...
1999_tsitsiklis_Optimal stopping of Markov processes Hilbert space theory, approximation algorithms, and an application to pricing high-dimensional financial derivatives
可以记录常用的linux命令,特别是比较长的,非常有用。使用方法:把该Q可执行文件考备份到...XAMPP: Stopping Apache with SSL... XAMPP: Stopping MySQL... XAMPP: XAMPP-ProFTPD is not running. XAMPP stopped.
Along with conventional problems of statistics and probability, the investigation of problems occurring in what is now referred to as stochastic theory of optimal control also started in the 1940s and...
该EarlyStopping类pytorchtool.py用于创建一个对象来跟踪验证损失的同时培养了模型。 每当验证损失减少时,它将保存模型的检查点。 我们在EarlyStopping类中将patience参数设置为在上次验证损失改善后要中断训练...
SRIM,全称为Stopping and Range of Ions in Matter,是一组用于计算离子在物质中停止和射程的程序。这个工具特别关注离子与原子间的碰撞,采用完整的量子力学处理方式来描述这一过程。SRIM始终将移动的原子视为...
[root@cy400 ~]# Starting mysqld daemon with databases from /var/lib/mysql ``` 第三步:用帐号登录 MYSQL 现在,我们可以使用 ROOT 帐号登录 MYSQL,以便进行密码破解。 ``` [root@cy400 ~]# mysql -u root ...
UCLA的stopping theory 课程讲义
实验评估显示,在一个包含65个节点对的网络中,使用1Mbit/s的802.11比特率传输1.0MB的文件时,ExOR的表现显著优于传统路由。具体来说,ExOR的中位数吞吐量达到了240Kbits/sec,而传统路由仅为121Kbits/sec,这意味着...
对于之前的版本,请参考相关文档《Stopping, starting, or restarting vCenter Server Appliances services》(编号:2054085)。 #### 列出vCenter Server Appliance服务 ##### 使用vSphere Web Client列出服务 ...
本文讨论了一种针对低密度奇偶校验码(LDPC)译码的新提前终止准则(SC),由刘文龙、马荣、李慧慧、杨德伟、匡镜明、王华等人提出。该终止准则基于译码迭代过程中不可靠变量节点个数的变化,目标是减少译码迭代次数...
总的来说,这个项目展示了如何利用Keras这一强大的工具来实现基于人工神经网络的数字识别功能,并通过Early-Stopping策略优化训练过程,提高了模型的效率和泛化能力。这对于想要深入理解深度学习和神经网络的初学者...
#### Starting and Stopping(启动与停止) 应用应该能够迅速启动,并在用户想要退出时优雅地停止。这部分内容提供了关于如何优化启动时间和处理意外中断的建议。 #### Layout(布局) 良好的布局能够使应用看起来...
Lesson No Stopping—because引导的原因状语从句PPT学习教案.pptx
信息安全_数据安全_Stopping the Proliferation of Io 网络信息安全 法律法规 安全研究 业务风控 应急响应
掺杂As2S8波导的Optical Stopping效应,杜丽萍,陈抱雪,实验研究了未掺杂以及低浓度掺锡和掺磷的As2S8薄膜波导的光阻断效应,提供了三种样品的光阻断响应曲线、室温退激实验数据和光谱测�
「业务安全」Stopping the Proliferation of IoT Botnets Is Dynamic Analysis the Answer - 移动安全 基础架构安全 数据安全 安全资讯 等级保护 WEB应用防火墙
Unit 4 Lesson 25 No stopping课堂练习(冀教版八上)2.doc