gpt4 book ai didi

ruby-on-rails - 设计+主动管理员重定向

转载 作者:行者123 更新时间:2023-12-04 16:48:17 25 4
gpt4 key购买 nike

我在为应用程序设置重定向时遇到麻烦。用户应转到其个人资料(用户/显示),而管理员应转到管理仪表板。我该如何设置?

当前出现以下错误:

 NameError in ActiveAdmin::Devise::SessionsController#create

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

应用程序 Controller
def after_sign_in_path_for(resource_or_scope)
if admin
redirect_to admin_dashboard_path
else
@user
end
end
end

最佳答案

您没有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

您也不应在此方法内重定向,而应仅返回devise可以使用的路径。

关于ruby-on-rails - 设计+主动管理员重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11385288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com