简体   繁体   English

设计current_user对象和会话变量

[英]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. 我在理解如何从模型/超级级别访问devise的current_user遇到了一些麻烦。 I want to set a few attributes as session vars (so I don't have to run an app-wide before_filter every time. 我想将一些属性设置为会话变量(因此我不必每次都运行应用程序范围的before_filter。

Would you recommend setting session keys (what's the proper term?), or can I modify the current_user object by tapping a devise method? 您是否建议设置会话密钥(正确的术语是什么?),还是可以通过点击设计方法来修改current_user对象?

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. 根据您要执行的操作,您可以始终覆盖current_user方法(在ApplicationController上设置)并进行任何适合您需要的修改。 More information here: 更多信息:

Where to override current_user helper method of devise gem 在哪里覆盖devise gem的current_user helper方法

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. 在上面的示例中,您可以始终使用devise_current_user返回的内容,然后在从重写的current_user方法返回之前修改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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