Module: Rack::Recaptcha::Helpers
- Defined in:
- lib/rack/recaptcha/helpers.rb
Constant Summary collapse
- DEFAULT =
{ :ssl => true }
Instance Method Summary collapse
-
#recaptcha_javascript(options = {}) ⇒ Object
Helper method to output the recaptcha javascript.
-
#recaptcha_valid? ⇒ Boolean
Helper to return whether the recaptcha was accepted.
-
#recaptcha_widget(options = {}) ⇒ Object
Helper method to output a recaptcha widget.
Instance Method Details
#recaptcha_javascript(options = {}) ⇒ Object
Helper method to output the recaptcha javascript. Available options:
:language - Set the language
26 27 28 29 30 31 32 |
# File 'lib/rack/recaptcha/helpers.rb', line 26 def recaptcha_javascript(={}) = DEFAULT.merge() path = [:ssl] ? Rack::Recaptcha::API_SECURE_URL : Rack::Recaptcha::API_URL params = '' params += "?hl=" + uri_parser.escape([:language].to_s) if [:language] %{<script src='#{path + params}'></script>} end |
#recaptcha_valid? ⇒ Boolean
Helper to return whether the recaptcha was accepted.
35 36 37 38 |
# File 'lib/rack/recaptcha/helpers.rb', line 35 def recaptcha_valid? test = Rack::Recaptcha.test_mode test.nil? ? request.env['recaptcha.valid'] : test end |
#recaptcha_widget(options = {}) ⇒ Object
Helper method to output a recaptcha widget. Available options:
:public_key - Set the public key. Overrides the key set in Middleware option
15 16 17 18 19 20 |
# File 'lib/rack/recaptcha/helpers.rb', line 15 def (={}) = DEFAULT.merge() [:public_key] ||= Rack::Recaptcha.public_key %{<div class="g-recaptcha" data-sitekey="#{[:public_key]}"></div>}.gsub(/^ +/, '') end |