5

我正在尝试将用户重定向到我的 root_path,它/允许未经身份验证的用户使用,但我似乎无法更改active admin.

我知道active admin用作devise身份验证机制,但我无法覆盖devise任何一个的默认值。

我在我的application_controller.rb(即使它应该是默认值)中尝试了以下内容:

# Overwriting the sign_out redirect path method
def after_sign_out_path_for(resource_or_scope)
  root_path
end

但我仍然在我的日志中看到这一点:

Started GET "/admin/logout?locale=fr" for 127.0.0.1 at 2012-06-07 11:30:15 -0400
  Processing by ActiveAdmin::Devise::SessionsController#destroy as HTML
  Parameters: {"locale"=>"fr"}
  AdminUser Load (0.4ms)  SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 1 LIMIT 1
   (0.1ms)  BEGIN
   (0.3ms)  UPDATE `admin_users` SET `remember_created_at` = NULL, `updated_at` = '2012-06-07 15:30:15' WHERE `admin_users`.`id` = 1
   (0.5ms)  COMMIT
Redirected to http://localhost:3000/admin
Completed 302 Found in 47ms

所以它让我回到登录页面。

4

3 回答 3

6

Fivell 的回答有点不正确,因为登录也被重定向到 root_path。更好的是,您可以覆盖特定的设计方法:

ActiveAdmin::Devise::SessionsController.class_eval do
  def after_sign_out_path_for(resource_or_scope)
    "/wherever-you-want"
  end
end
于 2013-07-03T23:27:54.707 回答
2

我为此做了一个猴子补丁

module ActiveAdmin::Devise::Controller

      def root_path
        "/"  #add your logic
      end
end

将此添加到初始化程序,它必须在注销后强制重定向到根 url。

于 2012-09-24T12:12:31.453 回答
2

这对我有用

# in app/admin/override.rb
ActiveAdmin::Devise::SessionsController.class_eval do
  def after_sign_in_path_for(resource)
    admin_dashboard_path
  end

  def root_path
    "/"  #add your logic
  end

  def after_sign_out_path_for(resource_or_scope)
    root_path
  end
end
于 2017-07-20T09:10:41.990 回答