2012-12-28 30 views
5

我有一个轨3.2应用程式设计2.1独特after_sign_out路径和轨道

我有使用设计(ADMINUSER和用户)

模型2种机型:

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 

我通过设计生成器为两个模型生成了单独的视图。 的意见/设计文件夹ADMINUSER(前新的要求更早实现月) 的意见/ Users文件夹的用户模型

signout后,我想重定向到匹配色器件模型的具体行动。下面的代码在application_controller.rb,但它正在申请,我想没有做这两种模式:

def after_sign_out_path_for(user) 
    user_landing_path 
end 

登出后,任一型号重定向到同一个目标网页,但我想有一个独特的目标为两个设计模型。

我该如何做到这一点?

回答

0

有些事情可以做:

case user.class 
when AdminUser.class 
    do_admin_sign_out() 
when User.class 
    do_user_sign_out() 
else 
    no_idea_who_you_are() 
end 

if user.kind_of? AdminUser 
    do_admin_thing() 
else 
    do_user_thing() 
end 

或者,你可以添加一个admin?检查,这两种模式,并检查,即:

if user.admin? 
    do_admin_thing() 
... 

我可能会做更晚的事,因为这可能会出现在其他地方,但这些都是你的选择。

+0

会在哪里这些代码有一项signout序列的范围内去寻找后的解决方案?我可以看到这些检查是在特定的基础上进行的,但不确定它在这种情况下适用于我在Devise引擎中使用控制器的情况 – koa