Redirecting
suggest changeAssuming the route:
resources :users, only: [:index]
You can redirect to a different URL using:
class UsersController < ApplicationController
def index
redirect_to "http://stackoverflow.com/"
end
end
To go back to the previous page:
redirect_to :back
redirect_to :back was removed in Rails 5.1. Use redirect_back:
redirect_back fallback_location: "http://stackoverflow.com/"
That uses the Referer header (HTTP_REFERER in Rack). The header is spelled with one r. If the browser sends no referrer, Rails redirects to fallback_location.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents