LoginSignup
0
0

rails authenticate_user!の使い方

Posted at

image.png

1:authenticate_user!とは
①deviseのメソッドである。
②ユーザーがログインしているかどうかを確認し、ログインしていない場合はユーザーをログインページにリダイレクトする。

2:使い方の一例
before_action :authenticate_user!, except: [:show, :index]

上記のコードの意味:すべてのアクションが実行される前に、ユーザーがログインしているかを確認する。ただし、show・indexアクションが呼び出された場合は、除くという意味となります。
(例:Twitterはログインしていなくても、ツイートの一覧、ツイートの詳細は見ることができる)

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