Module: NewGoogleRecaptcha::ViewExt

Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/new_google_recaptcha/view_ext.rb

Instance Method Summary collapse

Instance Method Details

#include_recaptcha_jsObject



5
6
7
8
9
# File 'lib/new_google_recaptcha/view_ext.rb', line 5

def include_recaptcha_js
  raw %Q{
    <script src="https://www.google.com/recaptcha/api.js?render=#{NewGoogleRecaptcha.site_key}"></script>
  }
end

#recaptcha_action(action) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/new_google_recaptcha/view_ext.rb', line 11

def recaptcha_action(action)
  id = "new_google_recaptcha_token_#{SecureRandom.hex(10)}"
  raw %Q{
    <input name="new_google_recaptcha_token" type="hidden" id="#{id}"/>
    <script>
      grecaptcha.ready(function() {
        grecaptcha.execute("#{NewGoogleRecaptcha.site_key}", {action: "#{action}"}).then(function(token) {
          document.getElementById("#{id}").value = token;
        });
      });
    </script>
  }
end