Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ambethia's reCAPTCHA plugin on Rails 3. Override flash message div defaults?

I have ambethia's reCAPTCHA plugin on Rails 3 working. Does anyone know how to override it's flash message markup? I'd like to reuse my own flash_error div id instead of using the plugin's flash_recaptcha_error div id:

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

Also, how would you clean up this controller#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

Thanks for reading my question.

like image 599
BasicObject Avatar asked Jan 31 '11 03:01

BasicObject


1 Answers

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

For example :

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

Maybe it could help you. Thanks

like image 69
Agung Prasetyo Avatar answered Oct 14 '22 02:10

Agung Prasetyo