LoginSignup
0
0

More than 1 year has passed since last update.

【Rails】ログイン前ユーザーのアクセス制限機能

Last updated at Posted at 2021-05-07

はじめに

deviseを利用したログイン前のユーザーのアクセス制限機能の実装についての備忘録です。
初学者のため間違った知識を公開している可能性もあるため遠慮なく指摘して頂ければと思います。
  
  

手順

基本的には下記の記述を任意のコントローラーに追加することで実装できる。

application_controller.rb
before_action :authenticate_user!

  
  
一部のページをアクセス制限の対象から除外する場合は以下のように記述する。

application_controller.rb
before_action :authenticate_user!, except: [:top]

  
  
このようにオプションとしてexcept: [:アクション名]を使用することでトップページだけはログイン前でもアクセス可能になる。

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