Ask A Question

Notifications

You’re not receiving notifications from this thread.

ActionText attachments not visible in Trix editor after domain migration

Andrew Broad asked in Rails

Hi All,

We recently moved domains and have noticed an issue with how ActionText attachments are displayed in the Trix editor. They display correctly in the show view, just not in the editor.

Article has_rich_text :body

On inspection we see that the body html still references the old domain which then becomes the src for the Trix editor img tag.

On the show view while the action-text-attachment url is still pointing to the old domain, the img src value points to the new one.

Any ideas why it works in show but not in the editor?

Thanks

Reply

Trix editor html extract, shortened for brevity.

<input type="hidden" name="article[body]" id="article_body_trix_input_article_10" value="...https://app.ptxperformance.co.uk/rails/active_storage/blobs/...<img src=&quot;https://olddomain/rails/active_storage/blobs/...<figure data-trix-attachment=&quot;{...url&amp;quot;:&amp;quot;https://olddomain/rails/active_storage/blobs/...<img src=&quot;https://olddomain/rails/active_storage/blobs/...</div>"><trix-toolbar id="trix-toolbar-1"><div class="trix-button-row">
<trix-editor class="customized-min-height" id="article_body" input="article_body_trix_input_article_10" data-direct-upload-url="https://newdomain/rails/active_storage/direct_uploads" data-blob-url-template="https://newdomain/rails/active_storage/blobs/redirect/:signed_id/:filename" ... data-trix-attachment="{&quot;contentType&quot;:&quot;image/png&quot;,&quot;filename&quot;:&quot;image.png&quot;,&quot;filesize&quot;:218212,&quot;height&quot;:1338,&quot;previewable&quot;:true,&quot;sgid&quot;:&quot;BAh7CEkiCGdpZAY6BkVUSSIwZ2lkOi8vcHR4L0FjdGl2ZVN0b3JhZ2U6OkJsb2IvNzY_ZXhwaXJlc19pbgY7AFRJIgxwdXJwb3NlBjsAVEkiD2F0dGFjaGFibGUGOwBUSSIPZXhwaXJlc19hdAY7AFQw--cce3d784b414afc965a7c8b033de543ac2d66258&quot;,&quot;url&quot;:&quot;https://olddomain/rails/active_storage/blobs/.../image.png&quot;,&quot;width&quot;:750}" data-trix-content-type="image/png" data-trix-id="83" data-trix-attributes="{&quot;caption&quot;:&quot;View Instructions menu&quot;,&quot;presentation&quot;:&quot;gallery&quot;}" class="attachment attachment--preview attachment--png" data-trix-mutable="true"><img src="https://olddomain/rails/active_storage/blobs/.../image.png" data-trix-mutable="true" width="750" height="1338"...
Reply

I'm having the same problem. @AndrewBroad, did you find a solution?

Reply

I found a solution. The old domain is embeded in RichText body, so it must be replaced by the new one, running this from rails console:

ActionText::RichText.where("body like '%https://olddomain%'").each do |t|
  t.update body: t.body.gsub('https://oldomain', 'https://newdomain.com')
end
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.