・ Rubis: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ Système d'exploitation: macOS Catalina
Ce qui suit a été mis en œuvre.
・ Présentation mince ・ Introduction de Bootstrap 3
Terminal
$ rails g migration AddIsValidToUsers is_valid:boolean
~_add_is_valid_to_users.rb
class AddIsValidToUsers < ActiveRecord::Migration[5.2]
def change
# 「default:"vrai" et "nul":Ajout de "faux"
add_column :users, :is_valid, :boolean, default: true, null: false
end
end
Terminal
$ rails db:migrate
user.rb
#Postscript
enum is_valid: { 'Efficacité': true, 'Retiré': false }
def active_for_authentication?
super && self.is_valid == 'Efficacité'
end
enum is_valid: { 'Efficacité': true, 'Retiré': false }
def active_for_authentication?
super && self.is_valid == 'Efficacité'
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)
if (user.valid_password?(params[:user][:password]) && (user.active_for_authentication? == true))
redirect_to new_user_session_path
end
Affichez les messages flash à l'aide du composant d'alerte Bootstrap 3.
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'
|Fermer
Recommended Posts