0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

authenticate_user!メソッド

Posted at

authenticate_user!メソッドとは

ログイン状態によって表示するページを切り替えるdeviseのメソッドで

ユーザーがログインしていなければ、そのユーザーをログイン画面に遷移させる事が出来ます
以下のようにcontroller内にbefore_actionを記述する事で、アクションを実行する前にログインしていなければログイン画面に遷移させられます。

ruby
before_action :authenticate_user!
indexアクションではログインをしていなくても閲覧できるようにしたい場合は以下のように記述する
ruby indexはログインせずに閲覧できる
before_action :authenticate_user!, except: :index
このように複数のアクションにも適用する事も出来ます
ruby indexとshowをログインせずに閲覧できる
before_action :authenticate_user!, except: [:index, :show]
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?