Here I'll show you
- How to override devise registrations_controller(related to create/update user account)
- How to change redirect path after updating user
I created a file under users/registrations_controller.rb
.
class Users::RegistrationsController < Devise::RegistrationsController
end
# app/config/routes.rb
devise_for :users, :controllers => {:registrations => "users/registrations"}
I assume you already use rails generate devise:views
generated devise views.
Move views/devise/registrations
folder to views/users
I guess that's it.
After updated user, by default you'll be redirected to root path. I want to change the path if my user is a teacher(one of roles), here is the code.
If you check the devise source code, you'll find the update
looks like this:
class Devise::RegistrationsController < ApplicationController
#...
protected
# The path used after sign up. You need to overwrite this method
# in your own RegistrationsController.
def after_sign_up_path_for(resource)
after_sign_in_path_for(resource)
end
end
So now we know what method to override: after_sign_up_path_for
class Users::RegistrationsController < Devise::RegistrationsController
def after_update_path_for(resource)
case resource
when :user, User
resource.teacher? ? another_path : root_path
else
super
end
end
end
http://stackoverflow.com/questions/3546289/override-devise-registrations-controller
If you override the devise controller do you no longer get the default devise logic?
Do I need to rewrite authentication logic from scratch?