上传到 ActionText 文本区域的图像未正确链接到 S3

Images uploaded into ActionText text area not linking correctly to S3

我在使用 image_processing gem 将 ActionText 与图像上传结合使用。但是,当上传图像时,它们不会转到 Active Storage 中设置的 S3。

所有其他图像上传工作正常,并按预期进入我的 S3 存储桶。它只是上传到不使用 S3 URL 的 ActionText 编辑器的图像。然而,它们确实进入了正确的桶。我无法在 blob 元素中更改或访问 URL。

我假设初始化程序或配置中有一个我无法找到的设置,但我无法通过文档或 google.

找到它

blob 当前使用的 URL 是 rail/active_storage/ 存储 URL 我需要它来使用我在 [=21] 中设置的 S3 URL =] 文件。

原来我可以编辑 _blob.html.erb 文件中的 URL。首先,我必须检查我是否在生产中。一旦我确认我能够构建 URL 以使用 blob.key.

从 S3 抓取
  <% if blob.representable? %>
    <% if Rails.env == 'production' %>
      <img class: "post-actiontext-image" src="https://<%= ENV['S3_BUCKET'] %>.s3-<%= ENV['AWS_REGION'] %>.amazonaws.com/<%= blob.key %>" />
    <% else %>
      <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]), class: "post-actiontext-image" %>
    <% end %>
  <% end %>