Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Overall: Its a regression with Sprockets 2. Read on for an explanation and solution.</p> <h3>How Debugging works internally</h3> <p>Assume you have a file called <code>vendor.js</code> with the following:</p> <pre><code># vendor.js //= require jquery //= require knockout //= ... some more requires function one() { } function two() { } // and some javascript code </code></pre> <p>First, let's see what the Asset Debugging does:</p> <ol> <li><p>Places a single <code>&lt;script src="vendor.js"&gt;</code> tag if debugging is disabled,</p> <p>(or)</p> <p>Places multiple <code>&lt;script src="vendor.js?body=1"&gt;, &lt;script src="jquery.js?body=1"&gt;, &lt;script src="knockout.js?body=1"&gt;, ...</code> when debugging is enabled</p></li> <li><p>The <code>body=1</code> is also an integral part of debugging. If you say <code>&lt;script src="vendor.js?body=1"&gt;</code> - it <em>only</em> renders the javascript inside <code>vendor.js</code>. It doesn't include any of the other <code>require ...</code> code.</p> <p>But if you hit <code>vendor.js</code> alone, without the <code>?body=1</code>, it includes all the <code>require ...</code> code as well.</p></li> </ol> <p>So a combination of the above two produce the necessary debugging output. What we want to do is, when we say <code>javascript_include_tag "vendor", :debug =&gt; false</code>, we want a single <code>&lt;script src="vendor.js"&gt;</code> tag with <em>NO</em> <code>?body=1</code> appended.</p> <h3>Explaining the Regression</h3> <p><a href="https://github.com/rails/sprockets-rails/blob/b522561d2d83b83c99e9aa54c8079fd1241fdf49/lib/sprockets/rails/helper.rb#L88" rel="noreferrer">The regressed code is here</a>. Specifically the buggy code is this one statement:</p> <pre><code>L88. if request_debug_assets? </code></pre> <p>Its checking request_debug_assets?, and then automatically setting <code>:debug =&gt; true</code> <a href="https://github.com/rails/sprockets-rails/blob/b522561d2d83b83c99e9aa54c8079fd1241fdf49/lib/sprockets/rails/helper.rb#L92" rel="noreferrer">further in line #92</a>. But <code>request_debug_assets?</code> is returning true, because that is being set at the application configuration level.</p> <p>This one statement should have ideally been:</p> <pre><code>L88. if request_debug_assets? &amp;&amp; options["debug"] != false </code></pre> <h3>Solution / Patch</h3> <p>I'll raise a pull request for the same, but until the pull request is reviewed and merged, you can do the following in an initializer:</p> <pre><code># config/initializers/sprockets_debug_patch.rb module Sprockets::Rails::Helper def javascript_include_tag(*sources) options = sources.extract_options!.stringify_keys # CHECK options["debug"] as well, not just the global assets.debug if request_debug_assets? &amp;&amp; options["debug"] != false # REST ALL SAME CODE AS ORIGINAL METHOD </code></pre> <p>Do the same for <code>stylesheet_include_tag</code> as well. Unfortunately there is no better way than copy/pasting the method code, but this resolves the problem.</p> <p>Throughout <code>Sprockets::Rails::Helper</code> class, you will find that it says <em>all this will be deprecated in Sprockets 3.x</em>. I don't know if Rails 4 is scheduled to ship with Sprockets 3.x. If so, then these patches might end up not being required.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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