Note that there are some explanatory texts on larger screens.

plurals
  1. PORails partial template using a custom handler is escaping html
    text
    copied!<p>I'm working on a Rails 3.1 app using JavascriptMVC and ejs templates within the client to do some complicated features on my application. Unfortunately ejs syntax is very similar to erb syntax, to the point where I can't keep the code in the same file (although if someone knows of a good way to do this, I'd be ecstatic). Ultimately I want to be able to apply some rails code within the ejs template (say for I18n) but at this point I will just settle for getting this to work</p> <p>Following the example from <a href="https://stackoverflow.com/questions/7049039/creating-a-blank-rails-3-1-templating-handler">this question</a> I have created a custom template handler that looks like this:</p> <pre><code>module CommonModel class Handler &lt; ActionView::Template::Handler include ActionView::Template::Handlers::Compilable def compile(template) template.source.inspect end end end ActionView::Template.register_template_handler :ejs, CommonModel::Handler </code></pre> <p>Then I created a partial template that has my ejs code in it: _jmvc_templates.html.ejs</p> <pre><code>&lt;script type="text/ejs" id="my_ejs_template"&gt; &lt;div&gt;Some ejs here&lt;/div&gt; &lt;/script&gt; </code></pre> <p>Within my existing template, I attempt to include my partial:</p> <pre><code>&lt;%= render 'path/to/my/ejs/templates/jmvc_templates' %&gt; </code></pre> <p>At this point, the file is included and my handler is used, but everything is escaped, so my div in my template gets rendered to the page like this: </p> <pre><code>&amp;lt;div%gt; </code></pre> <p>I'm sure I'm missing something obvious here, but I don't know what it could be... How can I get this template handler to just include my ejs based template without escaping all of the html in it?</p> <p><strong>Edit:</strong></p> <p>I've found that calling render with html_safe works:</p> <pre><code>&lt;%= render('path/to/my/ejs/templates/jmvc_templates').html_safe %&gt; </code></pre> <p>This seems like a kludge though - there has to be a way to get the erb renderer to treat text from my handler as html safe text.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload