Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This will happen when (1) your assets use paths, for example:</p> <pre><code>background:url(image_path('awesome-background.gif')) </code></pre> <p>and (2) your <code>asset_host</code> is set to a lambda/proc that requires the second argument (<code>request</code>).</p> <p>Your options are to either remove the <code>request</code> argument (if you don't actually use it) or make it optional (and handle the case where it is <code>nil</code>). This is easy in Ruby 1.9 (and should be easier, see notes):</p> <pre><code>config.action_controller.asset_host = -&gt;(source, request = nil, *_){ # ... just be careful that request can be nil } </code></pre> <p>If you want to be compatible with Ruby 1.8, there is no direct way to create a Proc/lambda with parameters with defaults, but you can use:</p> <pre><code>config.action_controller.asset_host = Proc.new do |*args| source, request = args # ... end </code></pre> <p>Or do it using a method:</p> <pre><code>def MyApp.compute_asset_host(source, request = nil) # ... end config.action_controller.asset_host = MyApp.method(:compute_asset_host) </code></pre> <p><em>Notes:</em></p> <ol> <li>Your block can return <code>nil</code> to signify the "default host", no need to use <code>"#{request.protocol}#{request.host_with_port}"</code></li> <li>In theory you don't need to specify the protocol; a url starting with <code>//</code> should use the default protocol (http or https). I'm saying "should" as it looks like <a href="http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/" rel="noreferrer">IE &lt;= 8 will download the css assets twice</a> and I've ran into problems with PDFkit.</li> </ol> <p>So in your particular case, your <code>asset_host</code> can be simplified to:</p> <pre><code>config.action_controller.asset_host = Proc.new { |source, request = nil, *_| "//assets#{(source.length % 4) + 1}.example.com" if request &amp;&amp; !request.ssl? } </code></pre> <p><em>Edit</em>: Use a lambda or else the <code>*_</code> to avoid a <a href="http://redmine.ruby-lang.org/issues/5694" rel="noreferrer"><strike>bug</strike> feature of Ruby</a>.</p>
 

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