I have a rails 3.2 app with Devise 2.1
I have 2 models using devise (AdminUser and User)
Models:
class AdminUser < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
I have generated separate views for both models via the devise generator. views/devise folder for AdminUser (implemented months earlier before new requirement) views/users folder for User model
After signout, I want to redirect to specific actions that match the devise models. The code below works in application_controller.rb but it is applying to both models which I want to do without:
def after_sign_out_path_for(user)
user_landing_path
end
Signing out of either model redirects to the same landing page, but i would like to have a unique destination for both devise models.
How can I achieve this?
I figured out what seems to be a solution after looking at some examples here http://eureka.ykyuen.info/2011/03/10/rails-redirect-previous-page-after-devise-sign-in/
def after_sign_out_path_for(resource_or_scope)
case resource_or_scope
when :user, User
user_landing_path
when :admin_user, AdminUser
admin_user_landing_path
else
super
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With