我有一个使用ActiveStorage的模型:
class Package < ApplicationRecord has_one_attached :poster_image end
如何创建包含初始poster_image文件副本的Package对象的副本.有点像:
original = Package.first copy = original.dup copy.poster_image.attach = original.poster_image.copy_of_file
解决方法
将源包的海报图像blob附加到目标包:
source_package.dup.tap do |destination_package| destination_package.poster_image.attach(source_package.poster_image.blob) end