将应用程序从 heroku 移至渲染。一旦 ENV 设置正确,一切似乎都工作正常。
但是我从heroku嵌入的actionText似乎被破坏了。渲染上的任何新嵌入都可以。
我在环境选项卡中正确设置了
RAILS_MASTER_KEY = the value in credientals.yml for secret_key_base
。
检查
Response Headers
没有location
有人遇到这个问题吗?有什么想法吗?
所以不到几个小时后,我通过谷歌搜索找到了解决方案。 我找到了两个帮助我解决这个问题的来源: 如何更新 ActionText 附件 和 Rails 6.1 -> 7 为 ActionText 附件提供 404
阅读 Rails 6.1 线程后,有人创建了几个方法来解决此问题:
# 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
这就是gorails github发挥作用的地方,使用这个rake任务减去用户语句,我在
app/lib/taks/action_text.rb
中创建了一个rake任务:
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
= 替换为您的网站
然后从渲染器的 shell 通过 ssh
或在仪表板上运行以下命令:rails action_text:refresh_embeds RAILS_ENV=prouction
所有嵌入都位于重定向中并在视图中呈现。