简体   繁体   中英

Accessing current_user devise method from rails controller

I'm using devise in a rails app I'm building. I'd like to get the ID of the user that is currently signed in, with current_user.id, in my controller, without passing it as a parameter from my view. Is there any way I can do this? Thanks

If you have installed Devise properly and have not broken something by overriding the Devise controllers, you should be able to access current_user.id from the controller. This method will only work if a user is signed in which you can test with the user_signed_in? method. Finally, this assumes that the resource name Devise is using is indeed user . That is the default, but it is possible to configure Devise to work with different resource names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM