Railsでの開発において、Deviseという認証gemを使用して複数モデルの認証を実装しました。
そこで、各モデルにおいて認証後にそれぞれで設定した個別ページにリダイレクトを行いたいです。
現在、いくつかの場合において、認証後に、直前にいたページにリダイレクトを行う処理までは実装しています。
Ruby
1class ApplicationController < ActionController::Base 2 after_filter :store_location 3 4 def store_location 5 if (request.fullpath != "/users/sign_in" && \ 6 request.fullpath != "/users/password" && \ 7 request.fullpath != "/shops/password" && \ 8 !request.xhr?) # don't store ajax calls 9 session[:previous_url] = request.fullpath 10 end 11 end 12 13 def after_sign_in_path_for(resource) 14 session[:previous_url] || root_path 15 end 16 17 def after_sign_out_path_for(resource) 18 session[:previous_url] || root_path 19 end 20end
ここから、Shop,User,Admin(ActiveAdmin)の3つのモデルにおいて、以下の様な仕様を設定したいです。
・User
◯新規登録後はuser#showにリダイレクト
◯ログイン後は直前のページにリダイレクト(実装済み)
・Shop
◯ログイン,新規登録後はshop#showにリダイレクト
・Admin
◯ログイン後はadmin_root_pathにリダイレクト
・共通
◯ログアウト後はroot_pathにリダイレクト
どのような記述を以って、上記の仕様を実装すればいいでしょうか。
ご回答、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/08/10 16:03