When using ActionMailer it uses a 'view' in the conventional path but how do you configure the 'view' that is being used (i.e. choose your own)?
It looks easy enough to change the 'layout' being used but where you do the same for the view?
When using ActionMailer it uses a 'view' in the conventional path but how do you configure the 'view' that is being used (i.e. choose your own)?
It looks easy enough to change the 'layout' being used but where you do the same for the view?
So if you have a UserMailer model, then you should have a directory app/views/user_mailer. Inside there you would have views based on the method names inside your model. So if you had a welcome_email method, you could have a template welcome_email.text.html.erb (or some such).
There is a pretty good explanation (which I cribbed from) here.
Add a template command in your model. E.g.:
class UserMailer < ActionMailer::Base
def welcome_email(user)
recipients user.email
from "Me<[email protected]>"
subject "Welcome!"
sent_on Time.now
body {:user => user, :url => "http://example.com/login"}
content_type "text/html"
## use some_other_template.text.(html|plain).erb instead
template "some_other_template"
end
end
Alternatively, you can also use the default views but specify a partial within the actual view, and thus use any partial you want just like any normal view.