3

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
 }
2
  • Can you show your inserts_js_enhanced_element.js.erb code? Commented Jan 10, 2013 at 13:13
  • @itsnikolay I added the structure, is this what you had in mind? Commented Jan 10, 2013 at 14:29

2 Answers 2

10

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

Sign up to request clarification or add additional context in comments.

Comments

3

Did you try just use this?

= render "inserts_js_enhanced_element"

2 Comments

and is the filenamed "_inserts_js_enhanced_element.js.erb" ?
@ReubenMallaby yes, it's _inserts_js_enhanced_element.js.erb, in the same folder, app/view/users, as the file where I make the render

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.