4

Rails 3でambetiaのreCAPTCHAプラグインが動作しています。誰もそれをフラッシュメッセージのマークアップをオーバーライドする方法を知っていますか?私の代わりに、プラグインのflash_recaptcha_errorのdivのidを使用しての私自身のflash_errorのdiv IDを再利用したいと思います:ambessiaのreCAPTCHAプラグインをRailsにインストールしました。3.フラッシュメッセージdivのデフォルトを上書きしますか?

<div id="flash_recaptcha_error">incorrect-captcha-sol</div> 

また、どのようにあなたは、このコントローラ#が作成クリーンアップするのでしょうか?

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 

私の質問をお読みいただきありがとうございます。

答えて

8

flash []は配列なので、その中の要素を削除することができます。 recaptcha gemを使用すると、フラッシュアレイには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 

多分それはあなたを助けることができます。おかげ

+1

これは働いていました。どうもありがとうございました。 – BasicObject

0

あなたが最初からユーザ認証システムを作っている場合は、このような何かをしなければならないことがあります。

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 
関連する問題