Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to customize the redirect after a successful account updation using devise

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 409
    Comment on it

    Here we want to render a custom page like the user's profile page after a successful account updation.The solution is fairly simple,however one  prerequisite i am assuming that we have already run rails generate devise:controller user command.

    Now consider Users::RegistrationsController and write after_update_path_for (resource) method as depicted below:

    class Users::RegistrationsController < Devise::RegistrationsController
    
       def after_update_path_for(resource)
          profile_path(resource)
        end
    
    end

    and config/routes.rb file should look like this :

    Rails.application.routes.draw do
       
         devise_for :users, :controllers => {:registrations => "users/registrations"}
         get 'profile' => 'users#profile'
    
    end

    So here after the  account updation instead of going to the default page as managed by devise gem we are rendered to the user's profile page as we have overridden the after_update_path_for (resource)  method.

    A slight deviation here , the after_sign_in_path method can also be added to the Users::SessionsController instead of the application_controller. Both are the accepted remedies for the usual problem of rendering a custom page after a successful login.

    class Users::SessionsController < Devise::SessionsController 
    
         def after_sign_in_path_for(resource) 
            profile_path
         end
    
    end

    So here after a successful login the user's profile page will be rendered and the same routes.rb file will suffice our purpose.

    Thank you .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: