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をインストールをすることで使用できます。

通常はbefore_actiontiと一緒に利用しアクションを実行する前にログインしていなければログイン画面に遷移させられます。
ただindexページ、詳細ページ、検索機能などはログインしていなくても見れる状態にしたいというのがあるので

before_action :authenticate_user!, except: [:index, :show, :search]

のようにexcept: [:index, :show, :search]をつけてあげればindex,show,searchアクションは除かれるのでログインしていなくても遷移させられることはありません。

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?