title: I can't edit post with image attachment using Trix Editor in Rails 5
body: <p>I'm using the gem <code>trix</code>.  I've followed a tutorial online for uploading images to the editor.  The image upload and storage works fine; however, when I go back to edit the post the trix-editor control doesn't show anything.  As if it is a blank post.  I also notice the following error in my console window of my browser but can't track down why it's happening.</p>
  
  <pre><code>VM931:1 Uncaught SyntaxError: Unexpected end of JSON input
      at JSON.parse (&lt;anonymous&gt;)
      at v (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:19)
      at g.processElement (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:19)
      at g.processNode (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:19)
      at g.parse (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:19)
      at Function.g.parse (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:19)
      at Function.c.fromHTML (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:20)
      at t.loadHTML (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:21)
      at new a (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:21)
      at HTMLElement.attachedCallback (trix.self-e0bc0a706de91177cd7d3cf457cc5cabf40fb5662c3e1fed55c0fbc56ca16e69.js?body=1:22)
  </code></pre>
  
  <p>I can post any of the code you'd like, I'll try and include what I think is helpful below.  I've also totally stripped out Turbolinks from the application thinking that maybe it was effecting it, but I saw the same results.</p>
  
  <p><strong>Here's the post's "body" value that isn't showing when using trix-editor</strong></p>
  
  <p><em>The form for the body attribute displays on the screen but it is blank</em></p>
  
  <pre><code>&lt;div&gt;test&lt;a href="/uploads/store/2cb381937ab8639f84b9ab32cfad1210.jpg" data-trix-attachment="{"contentType":"image/jpeg","filename":"3-sidesitting.jpg","filesize":67635,"height":453,"href":"/uploads/store/2cb381937ab8639f84b9ab32cfad1210.jpg","url":"/uploads/store/2cb381937ab8639f84b9ab32cfad1210.jpg","width":680}" data-trix-content-type="image/jpeg" data-trix-attributes="{"caption":"Yesssss I think it worked!"}"&gt;&lt;figure class="attachment attachment--preview attachment--jpg"&gt;&lt;img src="/uploads/store/2cb381937ab8639f84b9ab32cfad1210.jpg" width="680" height="453"&gt;&lt;figcaption class="attachment__caption attachment__caption--edited"&gt;Yesssss I think it worked!&lt;/figcaption&gt;&lt;/figure&gt;&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>assets/javascript/application.js</strong></p>
  
  <pre><code>//
  //= require rails-ujs
  //= require jquery
  //= require bootstrap
  //= require turbolinks
  //= require trix
  //= require_tree .
  </code></pre>
  
  <p><strong>assets/javascript/trix-uploads.coffee</strong></p>
  
  <pre><code>$(document).on 'turbolinks:load', -&gt;
  
    uploadAttachment = (attachment) -&gt;
      csrfToken = $('meta[name="csrf-token"]').attr('content')
      file = attachment.file
      form = new FormData
      endpoint = '/images'
      form.append 'Content-Type', file.type
      form.append 'image[image]', file
      xhr = new XMLHttpRequest
      xhr.open 'POST', endpoint, true
      xhr.setRequestHeader 'X-CSRF-Token', csrfToken
  
      xhr.upload.onprogress = (event) -&gt;
        progress = event.loaded / event.total * 100
        attachment.setUploadProgress progress
  
      xhr.onload = -&gt;
        if @status &gt;= 200 and @status &lt; 300
          data = JSON.parse(@responseText)
          return attachment.setAttributes(
            url: data.url
            href: data.url)
        return
  
      xhr.send form
  
    Trix.config.attachments.preview.caption =
      name: false
      size: false
    document.addEventListener 'trix-attachment-add', (event) -&gt;
      attachment = event.attachment
      if attachment.file
        return uploadAttachment(attachment)
      return
    return
  </code></pre>
  
  <p><strong>views/posts/_form.html.erb</strong></p>
  
  <pre><code>&lt;%= simple_form_for(@post) do |form| %&gt;
    &lt;%= form.error_notification %&gt;
  
    &lt;div class="form-inputs"&gt;
      &lt;%= form.input :title %&gt;
      &lt;%= form.input :author_id, as: :hidden, input_html: { value: current_user.id } %&gt;
      &lt;%= form.input :body, as: :trix_editor %&gt;
    &lt;/div&gt;
  
    &lt;div class="form-actions"&gt;
      &lt;%= form.button :submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>