2
2

More than 3 years have passed since last update.

【devise】サインイン・サインアップ後マイページに遷移する方法

Last updated at Posted at 2021-09-18

deviseでサインイン・サインアップ後マイページに遷移する方法

遷移先を指定する方法

サインインの際はapplication_controller.rbで、サインアップの際はregistrations_controller.rbでコードを記述します。

application_controller.rb
class ApplicationController < ActionController::Base

#サインイン後の遷移先を指定する方法
  def after_sign_in_path_for(resource)
    ○○_path #遷移先のパス
  end

end
registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController

#サインアップ後の遷移先を指定する方法
  def after_sign_up_path_for(resource)
    ○○_path #遷移先のパス
  end

end

サインアップ後マイページに遷移するように設定する

registrations_controller.rb

  def after_sign_up_path_for(resource)
    user_path(current_user.id)
  end

user_pathの後に(current_user.id)と記述することで、現在ログインしているユーザーのマイページへ飛ぶようになります。

user_path(current_user.id)
2
2
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
2
2