具有Devise和rails的多个模型的独特after_sign_out路径

koa*_*koa 5 ruby-on-rails devise ruby-on-rails-3

我有一个带有Devise 2.1的rails 3.2应用程序

我有两个使用设计的模型(AdminUser和User)

楷模:

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
Run Code Online (Sandbox Code Playgroud)

我通过设计生成器为两个模型生成了单独的视图.AdminUser的views/devise文件夹(在新要求之前几个月实现)用户模型的views/users文件夹

注销后,我想重定向到与设计模型匹配的特定操作.下面的代码适用于application_controller.rb,但是它适用于我想要做的两个模型:

def after_sign_out_path_for(user)
  user_landing_path
end
Run Code Online (Sandbox Code Playgroud)

退出任一模型都会重定向到同一个目标网页,但我希望两个设计模型都有一个唯一的目标.

我怎样才能做到这一点?

koa*_*koa 10

在查看了一些示例后,我想出了什么似乎是一个解决方案 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
Run Code Online (Sandbox Code Playgroud)