0
0

More than 3 years have passed since last update.

Rails ログイン機能

Posted at

環境

Rails 6.1.3
Ruby 2.6.5

ログインの仕組み

ログインページからメールアドレスやパスワードなどの情報をrailsに送信する。
送信された情報をもとに操作しているユーザを特定し、ログイン状態とする。

routes.rb
get "login"=>"users#login_form"/login_formアクションをlocalhost:3000/loginで読み出し
users_controller.rb
def login
@user=User.find_by(
email: params[:email]
password: params[:password])
end

フォームから入力されたemail,passwordから該当するユーザーを取得
userテーブルから入力された値に一致するユーザーを取得し、変数@userに代入

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0