Activeadmin not logging out when I click "logout"

I follow railscast instructions on installing activeadmin. After installation, I got two errors -

1) the number of arguments for sign_in is wrong - so I renamed my sign_in method to sign_in_user and fixed this problem.

then

2) wrong number of arguments for signed_in? - So, I renamed my signed_in? is_signed_in method? and it fixed this problem.

Now everything works, except when I click the logout button in activeadmin, it says “logged out successfully”, but the logout button is still in the upper corner, and it has not logged out.

I added these two things to my active_admin.rb file as suggested by people with similar problems:

config.logout_link_path = :destroy_admin_user_session_path 

and

 config.logout_link_method = :delete 

but still no luck. Here are my rake routes:

  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"} 

What am I missing? thanks!

+4
source share
4 answers

I had the same problem you encountered. I do not see in your code where you had the sign_in and signed_in methods? , but I suspect that you can have them in the SessionHelper class or the like, and that this helper is included in the ApplicationController like that?

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

It seems that ActiveAdmin also implements these methods, and overriding them in SessionHelper tricks it. You are on the right track and almost there! There is another way that you probably need to rename, then you do:

sign_out

Rename this too, then you should be able to enter and exit as before. Good luck

+1
source

For Devise users:

In /config/initializers/active_admin.rb

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

RESTART SERVER before testing changes.

+1
source
  • If you changed your configuration file, did you restart your rails application?

  • What does your route.rb look like? I am wondering if you have 2 devise_for e.g.

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

    If so, remove 1 of them.

  • make sure the exit link looks like this:

     <a href="/users/sign_out" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Logout</a> 
0
source

I solved this by changing the name of my sign_out method in my SessionHelper.

  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 

Then I had to change the destroyController destroy method to match

 def destroy sign_out_user ###CHANGE HERE redirect_to root_url end 

Also, if you use the method anywhere in your views. You will need to change it so that it matches the name of the new method.

0
source

All Articles