ActionText attachments not visible in Trix editor after domain migration
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
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="https://olddomain/rails/active_storage/blobs/...<figure data-trix-attachment="{...url&quot;:&quot;https://olddomain/rails/active_storage/blobs/...<img src="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="{"contentType":"image/png","filename":"image.png","filesize":218212,"height":1338,"previewable":true,"sgid":"BAh7CEkiCGdpZAY6BkVUSSIwZ2lkOi8vcHR4L0FjdGl2ZVN0b3JhZ2U6OkJsb2IvNzY_ZXhwaXJlc19pbgY7AFRJIgxwdXJwb3NlBjsAVEkiD2F0dGFjaGFibGUGOwBUSSIPZXhwaXJlc19hdAY7AFQw--cce3d784b414afc965a7c8b033de543ac2d66258","url":"https://olddomain/rails/active_storage/blobs/.../image.png","width":750}" data-trix-content-type="image/png" data-trix-id="83" data-trix-attributes="{"caption":"View Instructions menu","presentation":"gallery"}" 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"...
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