My rails mailer knows request and current_user

How about accessing @request and @current_user in your mailer


# 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

view raw

mailer_knows.rb

hosted with ❤ by GitHub

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s