There are certain cases in which we are doing a 301 redirect for pages from the controller. redirect_to product_show_path(updated_id)
, status: :moved_permanently. These redirections are working but we want to setup a custom meta tag when user is landing on a page by a 301 redirect. Is there any way to know it globally that is set it in the application.html.erb
file?
Asked
Active
Viewed 303 times
0

Roman Kiselenko
- 43,210
- 9
- 91
- 103

Adam Young
- 1,321
- 4
- 20
- 36
-
Maybe you can use `request.referrer` in landing controller? – inye Sep 08 '17 at 11:50
-
How can that help me in differentiating between a 301 and just regular page href? – Adam Young Sep 08 '17 at 11:51
-
I do not know how works you app, but if you can landing from other page maybe is not the correct method. Other options are [set-request](https://stackoverflow.com/questions/16654052/how-do-you-add-a-custom-http-header) or with [session](http://guides.rubyonrails.org/action_controller_overview.html#session) – inye Sep 08 '17 at 12:06
1 Answers
1
Use query string parameters to send additional data with a GET request (a 301 Redirect is always a GET request).
redirect_to product_show_path(updated_id, redirected_from: URI.encode(request.original_url))
This creates a param in the params hash just like any other:
<%= if params[:redirected_from].present? %>
You where redirected from <%= URI.decode(params[:redirected_from]) %>
<% end %>
This unlike the HTTP_REFERER
header works in all browsers.

max
- 96,212
- 14
- 104
- 165
-
Not 100% sure that you need to `URI.encode` the value or if rails does it automatically. – max Sep 08 '17 at 14:30