Activeadmin不注销,当我点击“注销”

问题描述:

我下面从有关安装activeadmin的railscast的说明。在安装时,我得到了两个错误 -Activeadmin不注销,当我点击“注销”

1)args作为sign_in数量无效 - 所以我改名为我sign_in方法sign_in_user并修复了这个问题。

然后

2)args作为signed_in的无效数? - 所以我重新命名了我的signed_in?方法is_signed_in?并解决了这个问题。

现在一切似乎只是当我点击注销按钮activeadmin工作,它说:“登出成功”,但注销按钮仍然在右上角,并没有记录我出去。

我加了这两样东西,每建议我active_admin.rb文件从人有类似问题:

config.logout_link_path = :destroy_admin_user_session_path 

config.logout_link_method = :delete 

但仍没有运气。这里是我的耙路线:

 admin_dashboard  /admin(.:format)        {:action=>"index", :controller=>"admin/dashboard"} 
      admin_comments GET /admin/comments(.:format)      {:action=>"index", :controller=>"admin/comments"} 
      admin_comments POST /admin/comments(.:format)      {:action=>"create", :controller=>"admin/comments"} 
     new_admin_comment GET /admin/comments/new(.:format)     {:action=>"new", :controller=>"admin/comments"} 
     edit_admin_comment GET /admin/comments/:id/edit(.:format)    {:action=>"edit", :controller=>"admin/comments"} 
      admin_comment GET /admin/comments/:id(.:format)     {:action=>"show", :controller=>"admin/comments"} 
      admin_comment PUT /admin/comments/:id(.:format)     {:action=>"update", :controller=>"admin/comments"} 
      admin_comment DELETE /admin/comments/:id(.:format)     {:action=>"destroy", :controller=>"admin/comments"} 
    new_admin_user_session GET /admin/login(.:format)       {:action=>"new", :controller=>"active_admin/devise/sessions"} 
     admin_user_session POST /admin/login(.:format)       {:action=>"create", :controller=>"active_admin/devise/sessions"} 
destroy_admin_user_session DELETE /admin/logout(.:format)      {:action=>"destroy", :controller=>"active_admin/devise/sessions"} 
     admin_user_password POST /admin/password(.:format)      {:action=>"create", :controller=>"active_admin/devise/passwords"} 
    new_admin_user_password GET /admin/password/new(.:format)     {:action=>"new", :controller=>"active_admin/devise/passwords"} 
    edit_admin_user_password GET /admin/password/edit(.:format)     {:action=>"edit", :controller=>"active_admin/devise/passwords"} 
     admin_user_password PUT /admin/password(.:format)      {:action=>"update", :controller=>"active_admin/devise/passwords"} 
        users GET /users(.:format)        {:action=>"index", :controller=>"users"} 
        users POST /users(.:format)        {:action=>"create", :controller=>"users"} 
        new_user GET /users/new(.:format)       {:action=>"new", :controller=>"users"} 
       edit_user GET /users/:id/edit(.:format)      {:action=>"edit", :controller=>"users"} 
         user GET /users/:id(.:format)       {:action=>"show", :controller=>"users"} 
         user PUT /users/:id(.:format)       {:action=>"update", :controller=>"users"} 
         user DELETE /users/:id(.:format)       {:action=>"destroy", :controller=>"users"} 
       attend_event POST /events/:id/attend(.:format)     {:action=>"attend", :controller=>"events"} 
    remove_attendee_event POST /events/:id/remove_attendee/:user_id(.:format) {:controller=>"events", :action=>"remove_attendee"} 
       edit_event POST /events/:id/edit(.:format)      {:controller=>"events", :action=>"edit"} 
        events GET /events(.:format)        {:action=>"index", :controller=>"events"} 
        events POST /events(.:format)        {:action=>"create", :controller=>"events"} 
       new_event GET /events/new(.:format)       {:action=>"new", :controller=>"events"} 
       edit_event GET /events/:id/edit(.:format)      {:action=>"edit", :controller=>"events"} 
        event GET /events/:id(.:format)       {:action=>"show", :controller=>"events"} 
        event PUT /events/:id(.:format)       {:action=>"update", :controller=>"events"} 
        event DELETE /events/:id(.:format)       {:action=>"destroy", :controller=>"events"} 
        sessions POST /sessions(.:format)       {:action=>"create", :controller=>"sessions"} 
       new_session GET /sessions/new(.:format)      {:action=>"new", :controller=>"sessions"} 
        session DELETE /sessions/:id(.:format)      {:action=>"destroy", :controller=>"sessions"} 
        signup  /signup(.:format)        {:controller=>"users", :action=>"new"} 
       create_event  /create_event(.:format)      {:controller=>"events", :action=>"new"} 
       my_events  /my_events(.:format)       {:controller=>"events", :action=>"my_events"} 
        signin  /signin(.:format)        {:controller=>"sessions", :action=>"new"} 
        signout  /signout(.:format)        {:controller=>"sessions", :action=>"destroy"} 
        contact  /contact(.:format)        {:controller=>"pages", :action=>"contact"} 
        about  /about(.:format)        {:controller=>"pages", :action=>"about"} 
         help  /help(.:format)        {:controller=>"pages", :action=>"help"} 
         root  /(.:format)         {:controller=>"pages", :action=>"home"} 

我在想什么?谢谢!

  1. 一旦你改变了它的配置文件,你有没有“重启”你的rails应用程序?

  2. 你的routes.rb是什么样的?我想知道你是否有2个devise_for语句,例如

    devise_for :admin_users, ActiveAdmin::Devise.config 
    #... other routes 
    devise_for :users 
    

    如果是这样,请删除其中的1个。

  3. 确保如果注销链接看起来象下面这样:

    <a href="https://*.com/users/sign_out" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Logout</a> 
    

我有,你都面临着同样的问题。我不能在你的代码中看到,你有sign_insigned_in?方法,但我怀疑你可能会把它们放在SessionsHelper类或类似的地方,并且那个帮助器就像这样包含在ApplicationController中?

class ApplicationController < ActionController::Base 
    protect_from_forgery 
    include SessionsHelper 
... 

看来ActiveAdmin也实现了这些方法,并覆盖它们在SessionsHelper沉船它。你走在正确的道路上,差不多在那里!还有一个方法,你可能需要重命名,然后你做:

SIGN_OUT

重命名一个过,那么你应该能够既登录和退出,就像以前一样。祝你好运!

我在我的SessionsHelper改变我SIGN_OUT方法的名称解决它。

def sign_out_user 
    current_user.update_attribute(:remember_token, 
           Adult.digest(Adult.new_remember_token)) 
    cookies.delete(:remember_token) 
    self.current_user = nil 
end 

然后我不得不改变我SessionsController破坏方法来匹配

def destroy 
    sign_out_user ###CHANGE HERE 
    redirect_to root_url 
end 

此外,如果您使用的是你的意见的任何地方的方法。您需要更改它,以便它与新的方法名称相匹配。

对于设计的用户:

/config/initializers/active_admin.rb

ActiveAdmin.setup do |config| 
    config.logout_link_path = :destroy_user_session_path 
    config.logout_link_method = :delete 

测试更改之前重新启动服务器