所以我一直在尝试解决这个问题一段时间,但我没有这样做。我有一个模型帖子 has_rich_text: body
class Post < ApplicationRecord
extend FriendlyId
friendly_id :title, use: :slugged
has_rich_text :body
has_rich_text :health_check
has_one_attached :cover_photo
has_many :post_tags, dependent: :destroy
has_many :tags, through: :post_tags
after_commit :add_default_cover, on: [:create, :update]
def add_default_cover
unless cover_photo.attached?
self.cover_photo.attach(io: File.open(Rails.root.join("app", "assets", "images", "default.png")), filename: 'default.png' , content_type: "image/png")
end
end
end
当我附加照片时它工作得很好,但是当我附加一个 gif 时,它会正确上传到编辑/新屏幕,我可以在富文本编辑器中看到 gif 的动画。但是,一旦我提交编辑/新表单,就会创建一个新变体作为图像,这就是显示帖子时使用的内容。当我检查我的存储系统时,我发现了图像和 gif 版本。
有谁知道为什么在提交表单时会发生这种情况?我想上传一个 gif 并在没有活动存储或操作文本更改它的情况下显示它。