Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. # ページ遷移で来たかどうか
  2. def page_transition?
  3. # !!! リダイレクトではリファラーは更新されないので、注意
  4.  
  5. # URL直打ち
  6. return true if request.referer.nil?
  7.  
  8. # ちゃんと遷移してきた
  9. current_path = request.path_parameters
  10. referer_path = Rails.application.routes.recognize_path(request.referer)
  11. current_path[:controller] != referer_path[:controller] || current_path[:action] != referer_path[:action]
  12. end
  13.  
  14. # getパラメーターの保持
  15. def redirect_condition
  16. if page_transition?
  17. # セッションあり/他ページからの遷移 の場合は前回requestを以てredirectする
  18. # 他ページ遷移を確認しておかないとクリアが効かなくなる(paramsなし=クリアという仕様になっているため)
  19. redirect_to game_reports_path(session[:query_parameters]) if session[:query_parameters]
  20. # 残念ながら、他ページからの遷移で永久機関になってしまう。
  21. else
  22. session[:query_parameters] = request.query_parameters
  23. end
  24. end
Add Comment
Please, Sign In to add comment