Redirecting

suggest change

Assuming 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents