在Rails上使用ambethia的reCAPTCHA插件3.覆盖flash消息div默认值?

我在Rails 3上运行了ambethia的reCAPTCHA插件。有谁知道如何覆盖它的flash消息标记?我想重用我自己的
flash_error
divid,而不是使用插件的
flash_recaptcha_error
divid:
<div id="flash_recaptcha_error">incorrect-captcha-sol</div>
另外,你如何清理这个控制器#create?
def create
  @post = Post.new(params[:post])
  respond_to do |format|
    if verify_recaptcha(:model => @post, :error => "reCAPTCHA incorrect. Try again.") && @post.save
      flash.now[:notice] = "Created "#{@post.title}""
      format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
    else
      flash.now[:error] = "Incorrect word verification. Are you sure you're human?"
      format.html { redirect_to(:back, :error => 'reCAPTCHA incorrect. Try again.') }
    end
  end
end
感谢您阅读我的问题。     
已邀请:
因为flash []是一个数组,你可以删除它里面的元素。当我们使用recaptcha gem时,flash数组包含recaptcha_error元素,所以你只需删除这个元素: 你的控制器里面有flash.delete(:recaptcha_error)。 例如 :
if  verify_recaptcha(:model=>@object,:message=>"Verification code is wrong", :attribute=>"verification code") && @object.save
  #your code if succes
else
  flash.delete(:recaptcha_error)
  #your code if its fail
end
也许它可以帮助你。谢谢     
如果您从头开始创建用户身份验证系统,则可能需要执行以下操作:
class UsersController < ApplicationController

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    respond_to do |format|
        if verify_recaptcha(:model => @user )
            if @user.save
                format.html { redirect_to root_url,  :notice => "You have Signed up!" }
            else
                format.html { render :new }
            end
        else
            flash.delete(:recaptcha_error)
            format.html { redirect_to( root_path , :flash => { :error => 'Please retry the two words of the reCaptcha' } ) }
        end
    end
  end
end
    

要回复问题请先登录注册