前提・実現したいこと
ログイン認証失敗時にリダイレクトするコードを組んでみたところ、エラーになってしまいました。
対処法をご教示お願いします。
該当のソースコード
・スーパークラス
ruby
1class CommonController < ApplicationController 2 3 before_action :do_init 4 5 def do_init 6 if !login then 7 redirect_to action: errorpage 8 end 9 end 10 11 # ログイン処理。 12 def login 13 # テスト用に認証を失敗させる。 14 false 15 end 16end
・継承クラス
ruby
1class SampleController < CommonController 2 def index 3 render plain: "認証成功" 4 end 5 def errorpage 6 render plain: "認証失敗" 7 end 8end
・エラーメッセージ
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
追記。
and returnをつけてもダメでした。
ruby
1redirect_to action: errorpage and return
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/12 02:32