Last active
January 1, 2016 12:38
-
-
Save amolpujari/8145426 to your computer and use it in GitHub Desktop.
My rails mailer knows request and current_user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/mailer_knows.rb | |
module MailerBefore | |
def before(hash) | |
hash.keys.each do |key| | |
define_method key.to_sym do | |
eval " @#{key} = hash[key] " | |
end | |
end | |
end | |
end | |
class ActionMailer::Base | |
extend MailerBefore | |
end | |
class ActionController::Base | |
before_filter :mailer_knows | |
def mailer_knows | |
ActionMailer::Base.before({ | |
:request => request, | |
:current_user => (current_user and current_user.dup) | |
}) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment