38
41

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsで遷移元のURLを取得する方法

Posted at

きっかけ

遷移前のページのURLによってページに表示するリンク先を分岐させる処理がしたかった。
その際に遷移前のページのURL取得方法を調べたのでメモ。

request.referer

遷移前のURLを取得するにはrequest.refererを使う。

<% if request.referer&.include?("/*******/**/") %>
  #前のページが指定したURLだった場合のリンク先
<% else %>
  #その他のリンク先
<% end %>

今回はこんな感じで使用しました。

参考

http://railsdoc.com/references/request
https://triple-underscore.github.io/RFC7231-ja.html#section-5.5.2

38
41
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
41

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?