ruby-on-rails – 如何定义自定义在两种不同模型的情况下设计失
发布时间:2020-12-16 21:58:55 所属栏目:百科 来源:网络整理
导读:我有两个模型User和ActiveAdmin,我想在其中应用我的设计集成. 我有我的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 re
|
我有两个模型User和ActiveAdmin,我想在其中应用我的设计集成.
我有我的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
这似乎很有效. 另外,可以在我的应用程序控制器中定义如: 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 但问题是如何在custom_failure.rb中使用此资源,以便我可以相应地重定向到登录用户登录或管理员登录?根据当前情况,它总是重定向到用户登录页面? 解决方法
尝试将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
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
