[Rails]「×××_path」ってどう編集すればいいの?
経緯
オリジナルアプリ作成に伴いログイン機能を実装しました。
その際、ログイン後にアクセスしたいページに遷移することができず、かなり時間をとられたので備忘録的に書き残します。
該当箇所
controrllers/application_controller.rb
class Users::SessionsController
def after_sign_in_path_for(resource)
XXXX_path #ご自身のpath
end
詰まった理由
controrllers/application_controller.rb
class Users::SessionsController
def after_sign_in_path_for(resource)
XXXX_path #ご自身のpath
end
・「×××_path」が何を表すのか分からなかった。
・「×××」に何を入れればいいか分からなかった。
分かったこと
・「×××_path」が何を表すのか分からなかった。
→ サインインした後に表示したいパス(URL)
・「×××」に何を入れればいいか分からなかった。
→ rails routesした際のPATHを入力
(※今回は赤線部分「bustersコントローラー」の「indexアクション」に紐づくViewをログイン後に表示したいので、赤戦部分のPATHを入力)
解決策
controrllers/application_controller.rb
class Users::SessionsController
def after_sign_in_path_for(resource)
busters_path #ご自身のpath
end
controrllers/application_controller.rb
class Users::SessionsController
def after_sign_in_path_for(resource)
busters_path #ご自身のpath
end
Author And Source
この問題について([Rails]「×××_path」ってどう編集すればいいの?), 我々は、より多くの情報をここで見つけました https://qiita.com/tuozhen389/items/608b90115864099d625b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .