ユーザーのアクセス範囲の制限
before_action :authenticate_user!
↑上記のコードを適用させたいコントローラーに設けることでそれぞれのアクションが実行される前にログイン画面に遷移されます。
例
before_action :authenticate_user!, only: [:new, :edit, :destroy]
before_action :authenticate_user!, except: [:index, :create, :show :update]
書き方はonlyでもexceptでも可能
もしくはapplication_controller.rb内に
before_action :authenticate_user!
と設けることで全ての動作の前にログインする画面に遷移するようになります。
今回説明したものは
Rails deviseで使えるようになるヘルパーメソッドの一つについてです。
↓こちらのリンクをご覧になるとわかりやすいと思います。おすすめです。
https://qiita.com/tobita0000/items/866de191635e6d74e392