0

Im using rails 3.2 and am having trouble using pre-created devise alongside active admin using a single model and an HABTM relation to a Role model.

I've followed this tutorial http://jaysonlane.net/2012/04/rails-devise-and-active-admin-single-user-model

And have altered a few things such as

unless current_user.admin?

for

unless current_user.roles.first.id==1 #checks if its an admin or not

If I log in with a regular user and try to access admin page through :300/admin I get a "Permission denied", which is a good thing.

However, if I log with an admin account(it sucessfully logs as an admin), and go to :3000/admin, it displays and error:

NoMethodError in Admin/dashboard#index
undefined method for 'destroy_admin_user_session_path'

changing it to:

config.logout_link_path = :destroy_current_admin_user_session_path
or
config.logout_link_path = :destroy_current_user_session_path

won't help either.

Thanks you in advance for your help

FIXED:

Had to run rake routes and alter the defaut active_admin initializer path and methods to my routes.

As for the error in logging out, apparently the default method for signing out with Active admin is :get. Therefore, an error occurs when clicking "Logout" in active admin. To fix this, go to config->initializers->active_admin.rb and add

config.logout_link_method= :delete

Hope this helps someone.

Thank you again @pjammer and @iain for your help in poiting me in the right direction. Regards

Silver
  • 693
  • 1
  • 10
  • 27
  • more stack please, such as where this `destroy_admin_user_session_path` was when called. Also you kept writing `destroy_CURRENT_admin_user_session_path` which is different than what was asked. – pjammer Apr 30 '12 at 12:25
  • @pjammer My destroy_current_admin_sessions_path is part of what was created automatically by Active Admin, by following @ iain advice, I ran rake routes and found the path was diferent. I am now able to login into Active Admin but when I click logout it gives me an error of user not found. Apparently, its is doing: "id"=>"sign_out" but in my User controller i am finding the user id with @ user=User.find(params[:id]). Any ideas? Thank you – Silver Apr 30 '12 at 14:20
  • The thing is,if I sign out using devise, the path is /users/sign_out and it works. If I logout inside Active Admin, the path is exacly the same, but returns the error I previously posted :/ – Silver Apr 30 '12 at 14:35
  • I think I know what the issue is. It is trying to sign_out using the method=>"get". Shouldn't it be "delete"? Active Admin created it but i can't seem to find it in the created code to modify it... – Silver Apr 30 '12 at 14:46

1 Answers1

1

Had to run rake routes and alter the defaut active_admin initializer path and methods to my routes.

As for the error in logging out, apparently the default method for signing out with Active admin is :get. Therefore, an error occurs when clicking "Logout" in active admin. To fix this, go to config->initializers->active_admin.rb and add

config.logout_link_method= :delete Hope this helps someone.

Thank you again @pjammer and @iain for your help in poiting me in the right direction. Regards

Silver
  • 693
  • 1
  • 10
  • 27