So no more than a couple hours later and googling I found a solution.
I found two sources that helped me solve this problem:
How To Update ActionText Attachments
and
Rails 6.1 -> 7 gives 404 for ActionText attachments
Reading the Rails 6.1 thread a person created a couple methods to fix this problem:
# After active storage urls are changed, use this to recreate all trix attachments
def self.refresh_trixes
ActionText::RichText.where.not(body: nil).find_each do |trix|
refresh_trix(trix)
end
end
# After active storage urls are changed, use this to recreate a specific trix attachments
def self.refresh_trix(trix)
return unless trix.embeds.size.positive?
trix.body.fragment.find_all("action-text-attachment").each do |node|
embed = trix.embeds.find { |attachment| attachment.filename.to_s == node["filename"] && attachment.byte_size.to_s == node["filesize"] }
node.attributes["url"].value = Rails.application.routes.url_helpers.rails_storage_redirect_url(embed.blob, host: "YOUR_DOMAIN")
node.attributes["sgid"].value = embed.attachable_sgid
end
trix.update_column :body, trix.body.to_s
end
I will admit I'm not 100% sure what this code is doing specifically the node.attributes
. My best guess is that something between the secret_key_base
and sgid
gets messed up and this just resets it.
This is where gorails github comes into play, using this rake task minus the user statement, I created a rake task in app/lib/taks/action_text.rb
:
namespace :action_text do
task refresh_embeds: :environment do
ActionText::RichText.where.not(body: nil).find_each do |trix|
next unless trix.embeds.size.positive?
trix.body.fragment.find_all("action-text-attachment").each do |node|
embed = trix.embeds.find { |attachment| attachment.filename.to_s == node["filename"] && attachment.byte_size.to_s == node["filesize"] }
# Files
if embed.present?
node.attributes["url"].value = Rails.application.routes.url_helpers.rails_storage_redirect_url(embed.blob, host: "My_Domain")
node.attributes["sgid"].value = embed.attachable_sgid
# User mentions
#elsif (user = User.find_by(id: Base64.decode64(node["sgid"])[/User\/(\d+)/, 1]))
#node.attributes["sgid"].value = user.attachable_sgid
end
end
trix.update_column :body, trix.body.to_s
end
end
end
My_Domain
= replace with your site
Then from the render's shell either via ssh
or on the dashboard I ran the following command: rails action_text:refresh_embeds RAILS_ENV=prouction
Presto all embeds are located in the redirect and rendered in view.