In my web application I am using the tinymce editor to allow users to create html emails. I have included a feature where they can save a template to the database so they can use it for multiple emails and access it where ever they want. But when I am trying to load the content that is stored in the database, back into the editor, it just inserts the html string. I want it so the html is rendered so they can see the template like it was when they saved it.
I think the problem has something to do with ERB because when I pass in a normal string it works fine, but when I use ERB to use an instance variable it just sets the content to the html string, not correctly formatted. Here is my code:
tinyMCE.init({
mode : "textareas",
theme : "advanced",
...
oninit : "loadTemplate"
});
function loadTemplate() {
tinyMCE.activeEditor.setContent("<%= @template %>");
}
This would just put <strong>Text Here</strong> in the editor, but this:
tinyMCE.init({
mode : "textareas",
theme : "advanced",
...
oninit : "loadTemplate"
});
function loadTemplate() {
template = "<strong>Text Here</strong>";
tinyMCE.activeEditor.setContent(template);
}
works perfectly fine and puts Text Here in the editor. What is going on here that is causing this problem?
If
@templatecontains an HTML String, rails will automatically escape it. To prevent the escaping, try addingraw, like so: