rails redirect_to :back not working rails redirect_to :back not working ruby-on-rails ruby-on-rails

rails redirect_to :back not working


Rails 5 has redirect_back, instead of redirect_to :back. It was changed as it used to raise an exception when request's HTTP_REFERER was not present.

So use this:

redirect_back fallback_location: root_path

You can change root_path to something else as per your requirements.


redirect_to :back was deprecated in Rails 5.0 (see PR) and then removed in Rails 5.1

Use the following instead:

redirect_back(fallback_location: root_path)