Skip to content

Instantly share code, notes, and snippets.

@amolpujari
Last active January 1, 2016 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amolpujari/8145426 to your computer and use it in GitHub Desktop.
Save amolpujari/8145426 to your computer and use it in GitHub Desktop.
My rails mailer knows request and current_user
# 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