views:

113

answers:

1

I have an Ajax form in my Rails app that contains the Recaptcha markup as provided by the helper in the Ambethia Recaptcha gem:

recaptcha_tags :ajax => true

On submit, the form hits a create action, which responds with the create.js.erb that contains the following:

$('#message-form').replaceWith("<%= escape_javascript(render('message')) %>");

The 'message' partial contains the same form markup that was originally rendered, including recaptcha_tags, but may also display if there were errors in the validation at this point.

In Firefox, the form gets re-rendered and displays a refreshed Captcha. But for some reason, in Webkit browsers (Safari and Chrome), the 'dynamic_recaptcha' Recaptcha element gets emptied, as if Recaptcha.create(public_key, element_id) never gets called.

In the Safari Developer console, I am able to call Recaptcha.create(public_key, element_id) and regenerate a Captcha.

Can anyone tell me what's going on here? Thanks.

A: 

i had the same problem and couldn`t get it to work with the recaptcha_tags in webkit browsers.

finally i followed the official guideline and wrote it like that (in HAML) ....


  1. in the layouts head tag:

    = javascript_include_tag "http://api.recaptcha.net/js/recaptcha_ajax.js"
    
  2. in the partial which was rendered via ajax:

    #dynamic_recaptcha
    :javascript
      Recaptcha.create('YOURPLUBLICKEY', document.getElementById('dynamic_recaptcha') , '')
    

http://code.google.com/apis/recaptcha/docs/display.html

mtin79
That worked, thanks!
cotopaxi