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?
undefined local variable or method request
for my mailer
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?
undefined local variable or method request
for my mailer
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
Request
The problem, as stated by Vimsha, is you're not able to access request
params outside of front-facing code
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)
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
I'd personally store the request data in the db (or redis if you only want it temporarily), and access it on demand