gpt4 book ai didi

ruby-on-rails - 在两个不同的模型用户和事件管理员的情况下,如何为设计定义自定义失败?

转载 作者:行者123 更新时间:2023-12-04 13:33:10 25 4
gpt4 key购买 nike

我有两个模型User和ActiveAdmin,我想在上面应用devise集成。

我有我的custom_failure.rb如下

class CustomFailure < Devise::FailureApp

def redirect_url
login_path
end

# def redirect_url
# root_path
# end

def respond
if http_auth?
http_auth
else
redirect
end
end
end

这似乎工作得很好。

另外,可以在我的 application controller中定义如下:
def after_sign_in_path_for(resource)
# case resource
if resource.is_a?(Admin)
admin_dashboard_path
else
root_path
end
end


def after_sign_out_path_for(resource_or_scope)
login_path
end

但是问题是如何在 resource中使用此 custom_failure.rb,以便我可以相应地重定向到 user loginadmin login登录?根据当前情况,它总是重定向到用户登录页面?

最佳答案

尝试将custom_failure.rb放入您的lib文件夹。然后确保文件已加载。可能您会尝试自动加载lib中的所有文件。

然后Redirect to a specific page

更新:

您必须使用作用域来解决此问题:

class CustomFailure < Devise::FailureApp 
def redirect_url
if warden_options[:scope] == :user
signin_path
else
new_admin_user_session_path
end
end
def respond
if http_auth?
http_auth
else
redirect
end
end
end

关于ruby-on-rails - 在两个不同的模型用户和事件管理员的情况下,如何为设计定义自定义失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14829654/

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