Access to current_user inside another rail engine

So here is my problem. I have a main application that has developed it, for which I create an engine. In the engine, I need current_user from the main application. I don’t know how I will get it, I tried this link , but to no avail. Any help would be great. If this is not recommended, please explain why.

+4
source share
2 answers

Solved

In the engine, you can access the main application using 'main_app'. In this variable, you have access to the current user, if you come up with. To access devise current_user, all you have to do is

main_app.scope.env['warden'].user

The utility stores the user inside the initial key in the session. Because it uses internal security to authenticate and store data in the session.

If there is an alternative solution, please let me know.

+2
source

If you use Rails 5.1+, there will be

main_app.scope.request.env['warden'].user

This is because env is deprecated.

+1
source

All Articles