The situation is that opposed to the classic setting (i.e. having an .rhtml file as the email template) the e-mail template I am using to send e-mail should be editable - i.e. there is a first version of the template (in the DB, or as an .rhtml_, it does not matter), which the user can edit from the Rails app, then the edited version should be saved and used to send the email.
While I don't think so this problem was not solved before, I was unable to find anything after heaps of googling - it seems everyone is just using the standard, one-html-for-all method.
Hi Peter,
I would bet that this situation comes up a lot. The best way I’ve found to handle this is to have your template in the DB. You can use ERB to process it like so:
email_body = ::ERB.new(email_template.gsub(“[{%”, “<%”).gsub(“%}]”,"
%>"), nil, “”).result(binding)
The gsubs are used because I recommend using the string [{% instead of <%. This allows you to use a WYSIWYG editor with minimum headache. Given that your making an interface for changing the email templates, one assumes, WYSIWYG is on the agenda too.
You still end up with a .rhtml file, but all in contains is <%= email_body %>
I’m sure others out there are doing something similar and would love to hear what they do.