Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add: hidden text_field in comment forms to anti spam

  • Loading branch information...
commit c9222cc649071466114422f8b5f6279c77220dfe 1 parent 41a6ac0
Xueqiao Xu authored
3  app/controllers/comments_controller.rb
View
@@ -2,6 +2,8 @@ class CommentsController < ApplicationController
before_filter :find_commentable
def create
+ return unless params[:spam].blank?
+
@comment = @commentable.comments.new(params[:comment])
@comment.user_agent = request.user_agent
@@ -18,7 +20,6 @@ def create
format.js
end
end
-
end
private
5 app/views/comments/_form.html.erb
View
@@ -2,6 +2,11 @@
:remote => true,
:html => { :id => "new_comment_#{commentable.id}" }) do |f| %>
<div class="field">
+ <%= text_field_tag :spam,
+ nil,
+ :style => 'display:none;' %>
+ </div>
+ <div class="field">
<%= f.text_field :author_name,
:id => nil %>
<%= f.label :author_name, 'Name (required)' %>
Please sign in to comment.
Something went wrong with that request. Please try again.