Last active
June 7, 2017 16:16
-
-
Save TakuyaHarayama/c31a3e0e17e5b0ecdfd60b0402ead80f to your computer and use it in GitHub Desktop.
前のページに戻るアクション
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_action :set_request_from | |
# どこのページからリクエストが来たか保存しておく | |
def set_request_from | |
if session[:request_from] | |
@request_from = session[:request_from] | |
end | |
# 現在のURLを保存しておく | |
session[:request_from] = request.original_url | |
end | |
# 前の画面に戻る | |
def return_back | |
if request.referer | |
redirect_to :back and return true | |
elsif @request_from | |
redirect_to @request_from and return true | |
end | |
end | |
end | |
# 各controllerで呼ぶ場合 | |
return_back and return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment