0

I'm writing some JS code inside something.js.haml as a response to a JS request. Sample code:

var users_list_container = jQuery("#user_list .manager_list");

if(users_list_container.length > 0) {
  alert(); //Doesn't work
  console.log("#{escape_javascript( render :partial => 'some' )}");
} else {
  //Some Code
}
alert();  //Works here

I get an ActionView::Template::Error (Illegal nesting: nesting within plain text is illegal.): line 5

If I remove spaces before console.log, the code doesn't throw this error. But, alert doesn't get executed inside if block, but it executes outside it.

Please suggest, how can I write JS if condition inside js.haml

Abhi
  • 4,123
  • 6
  • 45
  • 77

1 Answers1

1

You didn't follow haml syntax properly in you something.js.haml. You have to follow indentation in every view file. Below code work for you.

var users_list_container = jQuery("#user_list .manager_list");

if(users_list_container.length > 0) {
alert();
console.log("\#{escape_javascript( render :partial => 'some' )}");
} else {
\//Some Code
}
alert();
Dipak Gupta
  • 7,321
  • 1
  • 20
  • 32