・ 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 ・ Introduction of Bootstrap3 -Login function implementation ・ Devise Japanese localization
Terminal
$ rails g migration AddIsValidToUsers is_valid:boolean
~_add_is_valid_to_users.rb
class AddIsValidToUsers < ActiveRecord::Migration[5.2]
def change
# 「default:"true" and "null":Added "false"
add_column :users, :is_valid, :boolean, default: true, null: false
end
end
Terminal
$ rails db:migrate
user.rb
#Postscript
enum is_valid: { 'Effectiveness': true, 'Withdrawn': false }
def active_for_authentication?
super && self.is_valid == 'Effectiveness'
end
enum is_valid: { 'Effectiveness': true, 'Withdrawn': false }
valid
, define a method that returns true
.def active_for_authentication?
super && self.is_valid == 'Effectiveness'
end
session_controller.rb
session_controller.rb
#Postscript
protected
def reject_user
user = User.find_by(email: params[:user][:email].downcase)
if user
if (user.valid_password?(params[:user][:password]) && (user.active_for_authentication? == true))
redirect_to new_user_session_path
end
end
end
user = User.find_by(email: params[:user][:email].downcase)
2
is true, the login screen is displayed without performing login processing.if (user.valid_password?(params[:user][:password]) && (user.active_for_authentication? == true))
redirect_to new_user_session_path
end
Display flash messages using the Bootstrap 3 alert component.
sessions/new.html.slim
/Postscript
- if flash.present?
.alert.alert-danger.alert-dismissible.fade.in role='alert'
button.close type='button' data-dismiss='alert'
span aria-hidden='true'
| ×
- flash.each do |name, msg|
= content_tag :div, msg, :id => 'flash_#{ name }' if msg.is_a?(String)
p
a href='#' data-dismiss='alert'
|close
Recommended Posts