Access devise's current_user method in my controllers

227 views
Skip to first unread message

Steven Noble

unread,
Oct 2, 2015, 10:58:14 AM10/2/15
to Spree
I have just added Spree to my site to add a store.

I was using Authlogic for authentication but I'm switching over to Devise to fit in with Spree's defaults.

I have a number of controllers unrelated to the store that I need to restrict to admin users.

So I'm hoping to put a before filter like `redirect_to login_path unless current_user.try(:admin?)` in those controllers.

However I'm getting the message that `current_user is not defined`.

I'm figuring this might have something to do with Devise's helpers only being available in Spree's only controller because Device is installed through Spree, right?

And if so how can I bring this across to my other admin-only controllers?

Thanks,

Steven

Nhiem Nguyen

unread,
Oct 2, 2015, 12:02:45 PM10/2/15
to Spree
maybe you can try spree_current_user to see if it works.

Jason Fleetwood-Boldt

unread,
Oct 2, 2015, 1:27:44 PM10/2/15
to spree...@googlegroups.com
I think it's spree_current_user, read the spree_auth_devise source Gem for more info

You can alias method :current_user, :spree_current_user if you find that annoying (I do). 

I think we do that in our app with no problems.
-Jason



Reply all
Reply to author
Forward
0 new messages