0

的Rails插件的Recaptcha正确返回失败,还节省了我使用<a href="https://github.com/ambethia/recaptcha" rel="nofollow">recaptcha</a>和<a href="https://github.com/stefankroes/ancestry" rel="nofollow">ancestry</a>与评论模型模型

class Comment < ActiveRecord::Base 
    has_ancestry 
    attr_accessible :name, :content, :post_id, :parent_id 
    belongs_to  :post, :touch => true 
end 

但comments_controller.rb#创建将保存注释有或没有正确的验证码。

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 %> 

什么导致此?

回答

1

我不知道这是否是问题,但我想你想:

@comment = Comment.new(params[:comment]) 

随着Comment.create模型已经保存在你的if/else。

看答案here

+0

就是这样。谢谢! – BasicObject 2011-05-21 04:05:15

相关问题