title: Ruby on Rails & service worker
body: <p>I'm trying to use a service worker in my Ruby on Rails application.</p>
  
  <p>I need to use some erb features in my <code>app/javascripts/service-worker.js.erb</code> file. The service worker registration script looks like this:</p>
  
  <pre><code>var registerServiceWorker = function() {
    navigator.serviceWorker.register(
      '&lt;%= asset_path('service-worker.js') %&gt;',
      { scope: '/assets/' }
    )
    .then(function() {
      console.info('Service worker successfully registered');
    })
    .catch(function(error) {
      console.warn('Cannot register sercie worker. Error = ', error);
    });
  }
  </code></pre>
  
  <p>This does not work; I never get promise here:</p>
  
  <pre><code>navigator.serviceWorker.ready.then
  </code></pre>
  
  <p>I also tried <code>./</code> and <code>/</code> scopes but I got this error: </p>
  
  <blockquote>
    <p>DOMException: Failed to register a ServiceWorker: The path of the
    provided scope ('/') is not under the max scope allowed ('/assets/').
    Adjust the scope, move the Service Worker script, or use the
    Service-Worker-Allowed HTTP header to allow the scope.</p>
  </blockquote>
  
  <p>If I move my <code>service-worker.js</code> to the <code>public</code> folder, remove the <code>.erb</code> extension and change scope to <code>./</code>, everything works great, but I have no template engine there.</p>
  
  <p>Any suggestions?</p>