注销ActiveAdmin后重定向

时间:2012-06-07 15:36:58

标签: ruby-on-rails devise activeadmin

我正在尝试将用户重定向到我的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

因此它将我发回登录页面。

3 个答案:

答案 0 :(得分:5)

五个答案稍有不正确,因为登录也会重定向到root_path。更好的是,您可以覆盖特定的Devise方法:

ActiveAdmin::Devise::SessionsController.class_eval do
  def after_sign_out_path_for(resource_or_scope)
    "/wherever-you-want"
  end
end

答案 1 :(得分:2)

我为此做了一个猴子补丁

module ActiveAdmin::Devise::Controller

      def root_path
        "/"  #add your logic
      end
end

将此添加到初始值设定项,并且必须在注销后强制重定向到根URL。

答案 2 :(得分:1)

这对我有用

$med_pharmacy_id = $res['med_pharmacy_id'];
$consultation_med_id = $res['consultation_med_id'];

$update = "UPDATE consultation_med 
SET given_quantity = 0 
WHERE med_pharmacy_id = :mid
AND clinic_id = :cid 
AND consultation_med_id = :cmid";