title: Polling in ES6 and Rails
body: <p>What I'm doing: I'm trying to make a simple polling mechanism with ES6.</p>
  
  <p>Optimally, it should refresh a partial on <code>index</code> page every 5 seconds.</p>
  
  <p>It doesn't work. Logs write that the template was rendered, but nothing happens in browser.</p>
  
  <p><strong>app/javascript/packs/polls.js.erb:</strong></p>
  
  <pre><code>var sleep = time =&gt; new Promise(resolve =&gt; setTimeout(resolve, time))
  var poll = (promiseFn, time) =&gt; promiseFn().then(
               sleep(time).then(() =&gt; poll(promiseFn, time)))
  
  poll(() =&gt; new Promise(() =&gt; {
    fetch('/shows/refresh_results', {
    method: 'GET'
  
    })//.then(response =&gt; {
      // document.getElementById('top-shows-table-container').innerHTML = ("&lt;%= j render partial: 'shows/top_shows_table' %&gt;");
      // })
  }), 5000)
  </code></pre>
  
  <p><strong>app/controllers/application_controller.rb:</strong></p>
  
  <pre><code>class ShowsController &lt; ApplicationController
    def index
      @shows = Shows::OrderedByAverageReviewsScoreQuery.new.call
    end
  
    def refresh_results
      @shows = Shows::OrderedByAverageReviewsScoreQuery.new.call
  
      respond_to do |format|
        format.js
      end
  
      # render :index # this one doesn't work either
    end
  end
  </code></pre>
  
  <p><strong>app/views/shows/refresh_results.js.erb:</strong></p>
  
  <pre><code>$('#top-shows-table-container').html("&lt;%= render 'top_shows_table' %&gt;"); 
  CommentPoller.poll();
  </code></pre>
  
  <p>According to logs, the last file gets called. But nothing happens to page in browser.</p>
  
  <pre><code>Started GET "/shows/refresh_results" for 127.0.0.1 at 2018-12-05 03:06:06 +0300
  Processing by ShowsController#refresh_results as */*
    Rendering shows/refresh_results.js.erb
    Rendered shows/refresh_results.js.erb (0.5ms)
  Completed 200 OK in 6ms (Views: 3.6ms | ActiveRecord: 0.0ms)
  </code></pre>
  
  <p>I also tried inserting .erb code directly into <code>.polls.js</code>, which didn't work either. It is currently commented out. If I do uncomment it, it will produce this error:</p>
  
  <pre><code>ERROR in ./app/javascript/packs/polls.js.erb
  Module build failed: Error: rails-erb-loader failed with code: 1
      at ChildProcess.&lt;anonymous&gt; (/home/.../projects/leaderboard-challenge/node_modules/rails-erb-loader/index.js:125:16)
      at emitTwo (events.js:106:13)
      at ChildProcess.emit (events.js:191:7)
      at maybeClose (internal/child_process.js:920:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
  </code></pre>