0
0

More than 3 years have passed since last update.

ユーザーのアクセス範囲の制限

Posted at

ユーザーのアクセス範囲の制限

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

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