Pregunta

For including a piece of javascript that I only need on some pages, I put

 = javascript_tag do
   = render "inserts_js_enhanced_element.js.erb"

in my haml file. Now I get the warning in my tests:

DEPRECATION WARNING: Passing a template handler in the template name is 
deprecated. You  can simply remove the handler name or pass render
:handlers => [:erb] instead.`

However, when I change the line to

   = render "inserts_js_enhanced_element.js", :handlers => [:erb]

I get a new warning anyway, saying

 DEPRECATION WARNING: Passing the format in the template name is 
 deprecated. Please pass render with :formats => [:js] instead.

If I do change this to

 = render "inserts_js_enhanced_element", :handlers => [:erb], :formats => [:js]

it gives me the error

     ActionView::Template::Error:
   Missing partial application/inserts_js_enhanced_element with {:handlers=>[:haml, :builder, :erb, :coffee], :locale=>[:de], :formats=>[:html]}. 

Now the formats doesn't seem to have changed to :js and also the handlers are not only :erb. How should I input a JS-ERB correctly?

UPDATE:

The js.erb file has the form

 <% session_val = determine_session_val_from_config %>
 jQuery(document).ready(function() {
   //JS Code
 }
¿Fue útil?

Solución

Nice :) I think I found the answer on my own with this SO article

= render(:partial => 'inserts_js_enhanced_element', :handlers => [:erb], :formats => [:js])

Works, and doesn't give me the Deprecation warning

Otros consejos

Did you try just use this?

= render "inserts_js_enhanced_element"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top