Reputation: 1331
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?
Upvotes: 0
Views: 350
Reputation: 102036
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.
Upvotes: 1