・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina
The following has been implemented.
・ Slim introduction -Login function implementation
Send
site key
and secret key
and make a note of them.site key
and secret key
environment variables** ① Introduced "gem'dotenv-rails'" **
Gemfile
gem 'dotenv-rails'
Terminal
& bundle
** ② Create a ".env" file directly under the application **
Terminal
$ touch .env
** ③ Edit the .env
file **
.env
#Postscript
RECAPTCHA_SITE_KEY = 'Site key'
RECAPTCHA_SECRET_KEY = 'Secret key'
** ④ Edit the .gitignore
file **
.gitignore
/.env #Postscript
Terminal
$ touch config/initializers/recaptcha.rb
recaptcha.rb
#Postscript
Recaptcha.configure do |config|
config.site_key = ENV["RECAPTCHA_SITE_KEY"]
config.secret_key = ENV["RECAPTCHA_SECRET_KEY"]
end
resistration_controller.rb
resistration_controller.rb
#Postscript
prepend_before_action :check_captcha, only: [:create]
private
#If you do not perform reCAPTCA authentication, you will not be able to sign up and a validation message will be displayed.
def check_captcha
self.resource = resource_class.new sign_up_params
resource.validate
unless verify_recaptcha(model: resource)
respond_with_navigational(resource) { render :new }
end
end
slim:resistrations/new.html.slim
/Postscript
= recaptcha_tags
** ① Introducing Gem **
Gemfile
gem 'rails-i18n'
gem 'devise-i18n'
Terminal
$ bundle
** ② Edit ʻapplication.rb` **
application.rb
module Bookers2Debug
class Application < Rails::Application
config.load_defaults 5.2
config.i18n.default_locale = :ja #Postscript
end
end
** ③ Create / edit devise.ja.yml
file **
yml:devise.ja.yml
ja:
recaptcha:
errors:
verification_failed: 'ReCAPTCHA authentication failed.'
Recommended Posts