This blog is part of our Rails 5 series.
In Rails 4.x,
for going back to previous page we use
However sometimes we get
HTTP_REFERER is not present.
This works well when
HTTP_REFERER is present
and it redirects to previous page.
Issue comes up when
HTTP_REFERER is not present
and which in turn throws exception.
To avoid this exception we can use
and redirect to root url.
Improvement in Rails 5
In Rails 5,
redirect_to :back has been deprecated and instead
a new method has been added
To deal with the situation when
HTTP_REFERER is not present,
it takes required option
This redirects to
HTTP_REFERER when it is present
HTTP_REFERER is not present then
redirects to whatever is passed as