设计+主动管理重定向 [英] Devise + Active Admin Redirect

查看:221
本文介绍了设计+主动管理重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法为我的应用设置重定向。用户应该去他们的个人资料(用户/显示),管理员应该去管理仪表板..我如何设置?



目前正在收到以下错误: / p>

  ActiveAdmin :: Devise :: SessionsController#中的NameError创建

未定义的局部变量或方法`admin'对于#< ActiveAdmin :: Devise :: SessionsController:0x007febe12667e8>

应用程序控制器



$ {code> def after_sign_in_path_for(resource_or_scope)
如果admin
redirect_to admin_dashboard_path
else
@user
end
end
end


解决方案

你没有 admin 要访问的变量,您需要检查您要获取的参数。

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

你也应该在这个方法中重定向,只应该返回一个可以使用的路径。


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.

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.

这篇关于设计+主动管理重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆