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_js(opts = {}) ⇒ Object



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

def include_recaptcha_js(opts = {})
  badge = opts[:badge] ? "&badge=#{opts[:badge]}" : ""
  generate_recaptcha_callback +
    javascript_include_tag(
      "https://www.google.com/recaptcha/api.js?render=#{NewGoogleRecaptcha.site_key}&onload=newGoogleRecaptchaCallback#{badge}",
      defer: true
    )
end

#recaptcha_action(action) ⇒ Object



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

def recaptcha_action(action)
  id = "new_google_recaptcha_token_#{SecureRandom.hex(10)}"
  hidden_field_tag(
    'new_google_recaptcha_token',
    nil,
    readonly: true,
    'data-google-recaptcha-action' => action,
    id: id
  )
end