I’m using ActionMailer to send emails, but I’d like to use Sinatra’s Tilt rendering. I don’t know how to access Sinatra’s instance scope from outside Sinatra so I can do this:
class Mailer < ActionMailer
def test(address)
mail(:to=>address,
:body => 'turns out you need something here?') do |format|
details = erb(:myview)
format.text { details }
format.html { markdown(details) }
end
end
end
Hopefully you can see what I’m trying to do, but at the moment I’m getting a ‘method not found’ error. Any ideas how I can include Sinatra’s instance scope in the format block?
Thanks.
Here are several options.
Number One (kind of ugly)
Then in your app
Number Two
Define your Mailer class within your app’s helpers block. This should give it access to erb. I did something very similar with the plain-old mail gem. Except I defined a method rather than a whole class. Think it should still work, though.
Number Three
Look at Sinatra and/or Tilt’s code, follow erb up the stack until it no longer cares about the request instance, and duplicate it.