我有一个附件模型。每次在版本模型中更新附件时,我都想保存旧版本的附件。我在这方面取得了一些成功,但突然它停止了工作。
一切似乎都正常,但是当我尝试访问一个版本时,谷歌会说the x file cannot be displayed because it contains errors.
原始文件有效。
class Attachment < ActiveRecord::Base
mount_uploader :file, AttachmentUploader
has_many :versions
after_save :version
private
def version
versions.create(name: name, file: file) if file_changed?
end
end
class Version < ActiveRecord::Base
mount_uploader :file, VersionUploader
belongs_to :attachment
end
我尝试改变一些东西:
def version
versions.create(name: name, file: file, remote_file_url: file_url) if file_changed?
end
但这又产生了另一个错误: trying to download a file which is not served over HTTP
我不确定如何调试此问题。上传是普通的香草。
class AttachmentUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
process :set_content_type
storage :file
def store_dir
"#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end