LoginSignup
21

More than 5 years have passed since last update.

複数のdeviseモデルについてログイン後のページを設定する方法

Posted at

複数のdeviseモデルがあってそれぞれのログイン後のリダイレクト先を設定したい

前提

  • deviseモデルとして、AdminモデルとUserモデルがあるとする
  • Adminのログイン後のリダイレクト先はadmins_home_pathにしたい
  • Userのログイン後のリダイレクト先はusers_home_pathにしたい

実装

after_sign_in_path_forをオーバーライド

def after_sign_in_path_for(resource)
  case resource
  when Admin
    admins_home_path
  when User
    users_home_path
  end
end

参考にしたページ

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
21