I have a mailer class that wants to get the remote user. I access it my request.env['REMOTE_USER']
but get request not defined error
. i thought i were able to use request anywhere?
我有一个mailer类,它希望获得远程用户。我请求访问它。env['REMOTE_USER']但获取请求未定义错误。我以为我可以在任何地方使用请求?
undefined local variable or method request
for my mailer
未定义的本地变量或对我的mailer的方法请求。
1 个解决方案
#1
2
Why don't you try loading the remote user in your controller action, and either storing in the db, or redis when you're compiling your mailer
为什么不试着在控制器操作中加载远程用户,或者存储在db中,或者在编译邮件时redis ?
Request
请求
The problem, as stated by Vimsha, is you're not able to access request
params outside of front-facing code
正如Vimsha所指出的,问题在于您无法访问前置代码之外的请求参数
According to Rails, how do you access the raw request data at the absolute lowest level?, you can access the data directly from the middleware if you're working with a direct request (I.E your mailer is not delayed etc)
根据Rails,如何在绝对最低级别访问原始请求数据?,如果使用的是直接请求(I),则可以直接从中间件访问数据。E你的邮件没有被延迟等)
Structure
结构
Further to this, I would also question why you're accessing request-specific data directly from your mailer
除此之外,我还要问您为什么要直接从邮件发送器访问特定于请求的数据
The modular (DRY) nature of Rails means you need to be able to re-use as many of the assets as possible, meaning you may wish to use the mailer in a totally unrelated action
Rails的模块化(干燥)特性意味着您需要能够重用尽可能多的资产,这意味着您可能希望在完全不相关的操作中使用mailer
I'd personally store the request data in the db (or redis if you only want it temporarily), and access it on demand
我个人会将请求数据存储在db中(如果您只是临时需要它,也可以使用redis),并按需访问它
#1
2
Why don't you try loading the remote user in your controller action, and either storing in the db, or redis when you're compiling your mailer
为什么不试着在控制器操作中加载远程用户,或者存储在db中,或者在编译邮件时redis ?
Request
请求
The problem, as stated by Vimsha, is you're not able to access request
params outside of front-facing code
正如Vimsha所指出的,问题在于您无法访问前置代码之外的请求参数
According to Rails, how do you access the raw request data at the absolute lowest level?, you can access the data directly from the middleware if you're working with a direct request (I.E your mailer is not delayed etc)
根据Rails,如何在绝对最低级别访问原始请求数据?,如果使用的是直接请求(I),则可以直接从中间件访问数据。E你的邮件没有被延迟等)
Structure
结构
Further to this, I would also question why you're accessing request-specific data directly from your mailer
除此之外,我还要问您为什么要直接从邮件发送器访问特定于请求的数据
The modular (DRY) nature of Rails means you need to be able to re-use as many of the assets as possible, meaning you may wish to use the mailer in a totally unrelated action
Rails的模块化(干燥)特性意味着您需要能够重用尽可能多的资产,这意味着您可能希望在完全不相关的操作中使用mailer
I'd personally store the request data in the db (or redis if you only want it temporarily), and access it on demand
我个人会将请求数据存储在db中(如果您只是临时需要它,也可以使用redis),并按需访问它