Open jagthedrummer opened 3 days ago
I think this line is responsible for stripping the attachment info:
Here's a test that I ran to isolate that line:
rt = ActionText::RichText.find 6
irb(main):049> string = rt.body.to_trix_html
D, [2024-07-03T13:39:58.315078 #18698] DEBUG -- : ActiveStorage::Blob Load (0.3ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
=> "<div>This is a task with an image.<br><br>Here's the image:<br><br><figure data-trix-attachment=\"{"sgid":"eyJfcmFpbHMiOnsibWVzc2FnZS...
irb(main):050> string
=> "<div>This is a task with an image.<br><br>Here's the image:<br><br><figure data-trix-attachment=\"{"sgid":"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJalJuYVdRNkx5OW5ZVzFsTFdSaGVTOUJZM1JwZG1WVGRHOXlZV2RsT2pwQ2JHOWlMelVfWlhod2FYSmxjMTlwYmdZNkJrVlUiLCJleHAiOm51bGwsInB1ciI6ImF0dGFjaGFibGUifX0=--eaa74e1d5dc9c336f243a08ff9b56a1f7a55984a","contentType":"image/png","url":"http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--c7947d84eadfe128bf7bcd5b83245ad4d45e6491/octologo.png","filename":"octologo.png","filesize":37704,"width":200,"height":200,"previewable":true,"content":""}\" data-trix-attributes=\"{"presentation":"gallery"}\"></figure><br><br>Here's some text after the image</div>"
irb(main):052> string = string.gsub("bullettrain://", TEMPORARY_REPLACEMENT)
=> "<div>This is a task with an image.<br><br>Here's the image:<br><br><figure data-trix-attachment=\"{"sgid":"eyJfcmFpbHMiOnsibWVzc2FnZS...
irb(main):053> string
=> "<div>This is a task with an image.<br><br>Here's the image:<br><br><figure data-trix-attachment=\"{"sgid":"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJalJuYVdRNkx5OW5ZVzFsTFdSaGVTOUJZM1JwZG1WVGRHOXlZV2RsT2pwQ2JHOWlMelVfWlhod2FYSmxjMTlwYmdZNkJrVlUiLCJleHAiOm51bGwsInB1ciI6ImF0dGFjaGFibGUifX0=--eaa74e1d5dc9c336f243a08ff9b56a1f7a55984a","contentType":"image/png","url":"http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--c7947d84eadfe128bf7bcd5b83245ad4d45e6491/octologo.png","filename":"octologo.png","filesize":37704,"width":200,"height":200,"previewable":true,"content":""}\" data-trix-attributes=\"{"presentation":"gallery"}\"></figure><br><br>Here's some text after the image</div>"
irb(main):054> string = sanitize(string, tags: %w[div br strong em b i del a h1 blockquote pre ul ol li], attributes: %w[href])
=> "<div>This is a task with an image.<br><br>Here's the image:<br><br><br><br>Here's some text after the image</div>"
irb(main):055> string
=> "<div>This is a task with an image.<br><br>Here's the image:<br><br><br><br>Here's some text after the image</div>"
I have a
CLOUDINARY_URL
ENV var set, so images should be handled by Cloudinary.I'm trying to add an image to a
trix_editor
field.After saving the record, the image is not shown as being in the
description
field on the detail page.If I inspect the area where the image should be there seems to be no trace of it at all.
And when I edit the record again it does not appear in the editor.
When I first add the image to the
trix_editor
field I do see some activity in the server console. It looks like it's trying to use ActiveStorage instead of Cloudinary. But even so, the image seems to disappear.In a console I can see that an
ActiveStorage::Blob
record was created for the file:And I can see that a new file exists in the
storage/
directory matching the key of the blob that was created.I've also tried this same test without having the
CLOUDINARY_URL
ENV var in place and I still get the same result.