加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 03:02:33 所属栏目:百科 来源:网络整理
导读:我正在尝试使用 Sorcery安装 Rails Admin Gem进行身份验证而不是Devise. Rails管理员确实提供了一个钩子,您可以使用它来附加您自己的身份验证方法. Here是他们在他们的文档中提供的示例(使用warden): config.authenticate_with do warden.authenticate! :sc
我正在尝试使用 Sorcery安装 Rails Admin Gem进行身份验证而不是Devise.

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

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

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

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

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

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

如何正确设置?

解决方法

# config/initializers/rails_admin.rb
RailsAdmin.config do |config|
  config.authenticate_with do
    # Use sorcery's before filter to auth users
    require_login
  end
end

# app/controllers/application_controller.rb
class 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
  end
end

#config/initializers/rails_admin.rb
RailsAdmin.config do |config|
  ...
  config.parent_controller = 'ApplicationController'
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读