2011-10-12 97 views
4

我下面從有關安裝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"} 

我在想什麼?謝謝!

回答

0
  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://stackoverflow.com/users/sign_out" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Logout</a> 
    
1

我有,你都面臨着同樣的問題。我不能在你的代碼中看到,你有sign_insigned_in?方法,但我懷疑你可能會把它們放在SessionsHelper類或類似的地方,並且那個幫助器就像這樣包含在ApplicationController中?

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

看來ActiveAdmin也實現了這些方法,並覆蓋它們在SessionsHelper沉船它。你走在正確的道路上,差不多在那裏!還有一個方法,你可能需要重命名,然後你做:

SIGN_OUT

重命名一個過,那麼你應該能夠既登錄和退出,就像以前一樣。祝你好運!

0

我在我的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 

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

1

對於設計的用戶:

/config/initializers/active_admin.rb

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

測試更改之前重新啓動服務器