ruby-on-rails – 带有法术的Rails管理员

ruby-on-rails – 带有法术的Rails管理员,第1张

概述我正在尝试使用 Sorcery安装 Rails Admin Gem进行身份验证而不是Devise. Rails管理员确实提供了一个钩子,您可以使用它来附加您自己的身份验证方法. Here是他们在他们的文档中提供的示例(使用warden): config.authenticate_with do warden.authenticate! :scope => :adminendconfig.c 我正在尝试使用 Sorcery安装 Rails Admin Gem进行身份验证而不是Devise.

Rails管理员确实提供了一个钩子,您可以使用它来附加您自己的身份验证方法. Here是他们在他们的文档中提供的示例(使用warden):

config.authenticate_with do  warden.authenticate! :scope => :adminendconfig.current_user_method { current_admin }

我猜我在块中需要引用Sorcery用来验证用户的before_filter,这将是require_login.

但是,当我尝试这个并且我在注销时尝试访问/ admin时,出现了路由错误:

No route matches {:action=>"new",:controller=>"sessions"}

这可能是因为我在引擎内而不是在主应用程序中重定向.

如何正确设置?

解决方法
# config/initializers/rails_admin.rbRailsadmin.config do |config|  config.authenticate_with do    # Use sorcery's before filter to auth users    require_login  endend# app/controllers/application_controller.rbclass ApplicationController  # Overwrite the method sorcery calls when it  # detects a non-authenticated request.  def not_authenticated    # Make sure that we reference the route from the main app.    redirect_to main_app.login_path  endend#config/initializers/rails_admin.rbRailsadmin.config do |config|  ...  config.parent_controller = 'ApplicationController'end
总结

以上是内存溢出为你收集整理的ruby-on-rails – 带有法术的Rails管理员全部内容,希望文章能够帮你解决ruby-on-rails – 带有法术的Rails管理员所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1289597.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存