TIP: URL helper: Redirect to previous page
You can use
<%= link_to "return", request.referrer %>
to get to the previous page, but it is better to use
<%= link_to "return", :back %>
because the :back
thing provides the following code logic:
request.referrer || "javascript:history.back()"
<%= link_to "return", request.referrer %>
# Will generate an absolute url to origin page.
# If no previous page, will be an url to CURRENT page
javascript:history.back()
# The javascript leverages in-browser navigation.
# If no previous page, will be link to something like "New tab"
Did you like this article? Did it save you some time?