Ambetia reCAPTCHA plugin on Rails 3. Override default flash messages?

I have a reCAPTCHA amethia plugin for Rails 3. Does anyone know how to override this flash message markup? I would like to reuse my own id flash_error div instead of using the plugin flash_recaptcha_error div id:

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

Also, how would you clear this # create controller?

 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 

Thanks for reading my question.

+4
source share
2 answers

Since flash [] is an array, you can delete it inside. When we use the recaptcha gem, the flash array contains the recaptcha_error element, so you just delete this element only with: flash.delete (: recaptcha_error) inside your controller.

For instance:

 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 

Perhaps this may help you. Thanks

+8
source

If you are creating a user authentication system from scratch, you might need to do something like this:

 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 
0
source

Source: https://habr.com/ru/post/1337714/


All Articles