Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unique after_sign_out paths with multiple models with Devise and rails

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?

like image 878
koa Avatar asked Dec 28 '12 01:12

koa


1 Answers

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
like image 192
koa Avatar answered Nov 17 '22 10:11

koa