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
You say "So now we know what method to override: after_sign_up_path_for", but it looks like you defined "after_update_path_for" in "Users::RegistrationsController" near the bottom of the page. Am I missing something here?