class Comment < ActiveRecord::Base
has_ancestry
attr_accessible :name, :content, :post_id, :parent_id
belongs_to :post, :touch => true
end
但是comments_controller.rb#create 将保存带有或不带有正确验证码的评论。
def create
@comment = Comment.create(params[:comment])
if verify_recaptcha(:model => @comment) && @comment.save
flash[:notice] = "Replied"
redirect_to(post_path(:id => @comment.post))
else
flash[:error] = "Incorrect word verification. Are you sure you\'re human?"
redirect_to(post_path(:id => @comment.post))
end
end
这是表格:
<%= simple_form_for :comment, :url => { :controller => :comments, :action => "create" } do |f| %>
<%= f.input :post_id, :required => false, :as => :hidden %>
<%= f.input :parent_id, :required => false, :as => :hidden %>
<%= f.input :name, :label => false, :placeholder => "Name (optional)", :required => false %>
<%= f.input :content, :label => false, :placeholder => "Reply", :as => :text %>
<%= raw recaptcha_tags -%>
<%= f.button :submit, "Reply" %>
<% end %>
这可能是什么原因造成的?