简体   繁体   中英

Devise current_user object & session variables

I'm having a little trouble understanding how to access devise's current_user from a model/super level. I want to set a few attributes as session vars (so I don't have to run an app-wide before_filter every time.

Would you recommend setting session keys (what's the proper term?), or can I modify the current_user object by tapping a devise method?

Depending on what you're trying to do, you could always override the current_user method (which is set on the ApplicationController) and make whatever modifications will suit your needs. More information here:

Where to override current_user helper method of devise gem

In the above example, you could always take what devise_current_user returns and then modify it before returning from your overriding current_user method.

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