Module Recaptcha::ClientHelper
In: lib/recaptcha/client_helper.rb

Methods

Public Instance methods

Your public API can be specified in the options hash or preferably the environment variable RECAPTCHA_PUBLIC_KEY.

[Source]

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

[Validate]