How do you access a session from the ActionMailer class?

I have an application that can be accessed from two different URLs, and it looks / behaves a little differently, depending on which URL you use to access it. I can do this by storing the value in the session object and defining some of its solutions, for example, from which the paths are loaded.

This approach looked as if it would work until I needed to have another URL sent in emails. In a class that inherits from ActionMailer, I need to set default_url_options [: host] based on the value of the session variable. Rails raises the following error when I call a session from anywhere in the mailbox:

undefined local variable or `session 'method for ApplicationMailer: Class

A less desirable way to handle this is to pass the session variable into my mail program calls. I would rather not do this as it does not seem very dry and will require changes in most of my code.

+4
source share
1 answer

If you can bind the link to a session in the mailbox or not, I think that you have already found a suitable solution. Transmission in the context you want to use is preferable for several reasons.

  • The mail probably should not know about the session.
  • Suppose someday you have to send a lot of emails and process the package. You will return to where you are now to go into your context.
+3
source

All Articles