Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails View inserting js.erb file via render
    primarykey
    data
    text
    <p>For including a piece of javascript that I only need on some pages, I put </p> <pre><code> = javascript_tag do = render "inserts_js_enhanced_element.js.erb" </code></pre> <p>in my <code>haml</code> file. Now I get the warning in my tests:</p> <pre><code>DEPRECATION WARNING: Passing a template handler in the template name is deprecated. You can simply remove the handler name or pass render :handlers =&gt; [:erb] instead.` </code></pre> <p>However, when I change the line to </p> <pre><code> = render "inserts_js_enhanced_element.js", :handlers =&gt; [:erb] </code></pre> <p>I get a new warning anyway, saying</p> <pre><code> DEPRECATION WARNING: Passing the format in the template name is deprecated. Please pass render with :formats =&gt; [:js] instead. </code></pre> <p>If I do change this to </p> <pre><code> = render "inserts_js_enhanced_element", :handlers =&gt; [:erb], :formats =&gt; [:js] </code></pre> <p>it gives me the error </p> <pre><code> ActionView::Template::Error: Missing partial application/inserts_js_enhanced_element with {:handlers=&gt;[:haml, :builder, :erb, :coffee], :locale=&gt;[:de], :formats=&gt;[:html]}. </code></pre> <p>Now the formats doesn't seem to have changed to <code>:js</code> and also the handlers are not only <code>:erb</code>. How should I input a JS-ERB correctly?</p> <p>UPDATE:</p> <p>The js.erb file has the form</p> <pre><code> &lt;% session_val = determine_session_val_from_config %&gt; jQuery(document).ready(function() { //JS Code } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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