17
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails4.1でdeviseのログイン後のリダイレクト先を変更

Posted at

概要

Ruby On Rails4.1環境でdeviseを利用してログイン機能を実装していますが、
ログイン後にリダイレクトするパスを変更します。

実装

after_sign_in_path_forをオーバーライド

app/controllers/application_controller.rb
# 以下を追加
  # ↓メソッドの返り値がリダイレクト先のパスになります。
  def after_sign_in_path_for(resource)
    root_path
  end

補足

今回は例としてroot_pathを入れていますが、
ここではroot_pathのようにPathHelperでも、
'/menu/index'のようにURL指定でも、
何かしら複雑な処理を入れても構いません。

17
21
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
17
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?