I have a basic .js file with this inside it
//$('#show').html('<%= escape_javascript(render(:partial => 'show')) %>');
When the .js file is called, the code above gets executed and the partial is rendered even though it's commented out. When the code is deleted, the partial never gets rendered. The DOM remains unchanged, but I can see the partial being rendered by the server at the command line. What gives?
I had a similar issue and figured out a work around for what I wanted it for. Perhaps something like this will help you out!
Instead of commenting the lines of code out, try just building a logical operator that gives you an "on/off" toggle on the functions you want to run. I set mine up like this so I could turn off the script but keep it for future reference:
Since your variable is not equal to two, the if statement will not render out what's stored inside of it, effectively 'commenting' that code out for you! To turn it back on all you have to do is change the 'toggle' variable back to 2 (or whatever 'on' value you want). Just a little work around I found for myself, hope that helps!
You're commenting out the JavaScript--which executes on the client side.
The partial rendering happens on the server side, before the client ever sees the rendered JavaScript.
In other words, commenting out JavaScript has zero effect on the server-side processing. If you don't want the server-side string to be displayed, comment it out:
Let's assume the partial renders like this:
Escaping this for JavaScript will turn the newline into a
\n
(and would escape single- and double-quotes, etc.) leaving you with this on the client side:Whether or not the JS is commented out or not, the partial is going to render unless you comment out the results of the
escape_javascript
Ruby code.On the client side, if the JS is commented out, it shouldn't update
show
's HTML--are you saying it is?Check to see if this is the line or you have this call some place else:
Perhaps your escape_javascript function is inserting a newline? That would end the comment and cause anything after the newline to be executed.