authenticate_user!メソッド

自分の覚書。

authenticate_user!メソッドは、Deviseが提供しているメソッドで、これを使用してログイン有無のチェックができる。

class BlogsController < ApplicationController
  before_action :authenticate_user!
省略

 こうすることで、まずログインしているかをチェックし、ログインしていない場合はログイン画面に移動することになる。

ログインしていない場合=falseの場合は、new_user_session_pathに自動的にリダイレクトしてくれる。