Skip to content

How To: Customize the redirect after a user edits their profile

pnc edited this page Sep 12, 2011 · 9 revisions

Normally, after a user edits their profile they are redirected to the root_path. To have Devise redirect to a custom route after an update, follow these steps:

  1. Sub-class Devise's registration controller.
  2. Override the after_update_path_for(resource) method.
  3. Configure Devise's routing.

Example subclass/override (registrations_controller.rb):

class RegistrationsController < Devise::RegistrationsController

  protected

    def after_update_path_for(resource)
      user_path(resource)
    end
end

Example routing config (in routes.rb):

devise_for :users, :controllers => { :registrations => :registrations }

The above code, will redirect the user back to the edit page, after the form submits with success. Depending on how you have configured your registrations views (if at all) you may need to move them into a different package.

Alternatively, you can define user_root in your config/routes.rb:-

devise_for :users do
 get 'users', :to => 'users#show', :as => :user_root # Rails 3
end

Where 'users#show' is the controller/action you want to redirect to.

...or (though not quite as elegant) you can just add a new match clause to your config/routes.rb:

match 'user_root' => 'users#show'
Clone this wiki locally