Rudi Thiel
Rudi Thiel

Reputation: 2551

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

Upvotes: 2

Views: 1058

Answers (1)

Tom Aranda
Tom Aranda

Reputation: 6026

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.

Upvotes: 2

Related Questions