Module: Recaptcha::ClientHelper
- Defined in:
- lib/recaptcha/client_helper.rb
Instance Method Summary collapse
-
#recaptcha_tags(options = {}) ⇒ Object
Your public API can be specified in the
options
hash or preferably the environment variableRECAPTCHA_PUBLIC_KEY
.
Instance Method Details
#recaptcha_tags(options = {}) ⇒ Object
Your public API can be specified in the options
hash or preferably the environment variable RECAPTCHA_PUBLIC_KEY
.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/recaptcha/client_helper.rb', line 5 def ( = {}) # Default options key = [:public_key] ||= ENV['RECAPTCHA_PUBLIC_KEY'] error = [:error] ||= session[:recaptcha_error] uri = [:ssl] ? RECAPTCHA_API_SECURE_SERVER : RECAPTCHA_API_SERVER html = "" if [:display] html << %{<script type="text/javascript">\n} html << %{ var RecaptchaOptions = #{[:display].to_json};\n} html << %{</script>\n} end if [:ajax] html << %{<div id="dynamic_recaptcha"></div>} html << %{<script type="text/javascript" src="#{uri}/js/recaptcha_ajax.js"></script>\n} html << %{<script type="text/javascript">\n} html << %{ Recaptcha.create('#{key}', document.getElementById('dynamic_recaptcha')#{[:display] ? '' : ',RecaptchaOptions'});} html << %{</script>\n} else html << %{<script type="text/javascript" src="#{uri}/challenge?k=#{key}} html << %{#{error ? "&error=#{CGI::escape(error)}" : ""}"></script>\n} unless [:noscript] == false html << %{<noscript>\n } html << %{<iframe src="#{uri}/noscript?k=#{key}" } html << %{height="#{[:iframe_height] ||= 300}" } html << %{width="#{[:iframe_width] ||= 500}" } html << %{frameborder="0"></iframe><br/>\n } html << %{<textarea name="recaptcha_challenge_field" } html << %{rows="#{[:textarea_rows] ||= 3}" } html << %{cols="#{[:textarea_cols] ||= 40}"></textarea>\n } html << %{<input type="hidden" name="recaptcha_response_field" value="manual_challenge">} html << %{</noscript>\n} end end raise RecaptchaError, "No public key specified." unless key return html end |