简体   繁体   English

设计+主动管理重定向

[英]Devise + Active Admin Redirect

I am having trouble setting up the redirect for my application. 我无法为我的应用程序设置重定向。 Users should go to their profile (users/show) and admins should go to the admin dashboard.. How do i set this up? 用户应该转到他们的个人资料(用户/节目),管理员应该去管理仪表板..我该如何设置?

Currently getting the following error: 目前收到以下错误:

 NameError in ActiveAdmin::Devise::SessionsController#create

    undefined local variable or method `admin' for #<ActiveAdmin::Devise::SessionsController:0x007febe12667e8>

Application controller 应用控制器

def after_sign_in_path_for(resource_or_scope)
   if admin
   redirect_to admin_dashboard_path
  else
   @user
  end
 end
end

You don't have an admin variable to access, you need to check what the parameter is that you are being given. 您没有要访问的admin变量,您需要检查您所提供的参数是什么。

def after_sign_in_path_for(resource)
  stored_location_for(resource) ||
    if resource.is_a?(Admin)
      admin_dashboard_path
    else
      user_path(resource)
    end
end

You should also not redirect inside this method, it should only return a path that devise can use. 你也应该不是这个方法里面重定向,它应该只返回设计可以使用路径。

if resource.class == User
  root_path
elsif resource.class == AdminUser
  admin_root_path
else
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM