Permalink
Browse files

add: hidden text_field in comment forms to anti spam

  • Loading branch information...
1 parent 41a6ac0 commit c9222cc649071466114422f8b5f6279c77220dfe @qiao committed Sep 24, 2011
Showing with 7 additions and 1 deletion.
  1. +2 −1 app/controllers/comments_controller.rb
  2. +5 −0 app/views/comments/_form.html.erb
@@ -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
@@ -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)' %>

0 comments on commit c9222cc

Please sign in to comment.