I have an Action Mailer set up to render email using the body attribute of my email model (in the database). I want to be able to use erb in the body, but I cannot figure out how to display it in the sent email.
I can get the body as a string with this code
# models/user_mailer.rb def custom_email(user, email_id) email = Email.find(email_id) recipients user.email from "Mail It Example < admin@foo.com >" subject "Hello From Mail It" sent_on Time.now
I came across this article http://rails-nutshell.labs.oreilly.com/ch05.html which says that I can use render , but I can get render :text to work, not render :inline
# models/user_mailer.rb def custom_email(user, email_id) email = Email.find(email_id) recipients user.email from "Mail It Example < admin@foo.com >" subject "Hello From Mail It" sent_on Time.now
Update: Someone recommended using initialize_template_class in this thread http://www.ruby-forum.com/topic/67820 >. Now i have this for body
body :msg => initialize_template_class(:user => user).render(:inline => email.body)
It works, but I donβt understand it, so I tried to learn a private method, and there isnβt so much that makes me worry that this is a hack, and probably the best way. suggestions
source share