Skip to content

Instantly share code, notes, and snippets.

@skojin
Created May 18, 2010 09:21
Show Gist options
  • Save skojin/404809 to your computer and use it in GitHub Desktop.
Save skojin/404809 to your computer and use it in GitHub Desktop.
# recaptcha gem fail when load as ajax, do this in right way
module RecaptchaHelper
def ajax_recaptcha_script_url(options = {})
uri = options[:ssl] ? Recaptcha::RECAPTCHA_API_SECURE_SERVER : Recaptcha::RECAPTCHA_API_SERVER
"#{uri}/js/recaptcha_ajax.js"
end
# Your public API can be specified in the +options+ hash or preferably
# the environment variable +RECAPTCHA_PUBLIC_KEY+.
def ajax_recaptcha_tags(options = {})
# Default options
key = options[:public_key] ||= ENV['RECAPTCHA_PUBLIC_KEY']
raise Recaptcha::RecaptchaError, "No public key specified." unless key
display_options_json = (options[:display] || {}).to_json
html = ""
html << %{<div id="dynamic_recaptcha"></div>}
html << %{<script type="text/javascript">\n}
html << %{ Recaptcha.create('#{key}', 'dynamic_recaptcha', #{display_options_json});\n}
html << %{</script>\n}
return html
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment