Thinh Phan

Joined

10 Experience
0 Lessons Completed
0 Questions Solved

Activity

A little bit late but hope this will help others. In my case, I can't make the Request.js#get work, so I use fetch instead. The controller response as turbo-stream format so you must tell the client to render it - Turbo instance is automatically assigned to window.Turbo upon import import "@hotwired/turbo-rails"

    fetch(url, {
      method: 'GET',
      mode: 'cors',
      cache: 'no-cache',
      credentials: 'same-origin',
      headers: {
        'Accept': "text/vnd.turbo-stream.html",
        'X-CSRF-Token': csrfToken
      },
    })
    .then(response => response.text())
    .then(html => Turbo.renderStreamMessage(html)) // this will render the turbo-stream as HTML