Not sure what I am doing wrong. I am using rails 6 and attempting to clone a record and it's attached uploads. Any ideas why this is generating this error?
Model:
class Compitem < ApplicationRecord
belongs_to :user
has_many_attached :uploads, dependent: :destroy
end
Copy method
def copy
@source = Compitem.find(params[:id])
@source.deep_clone do |original, kopy|
if kopy.is_a?(Compitem) && original.uploads.attached?
original.uploads.open do |tempfile|
kopy.uploads.attach({
io: File.open(tempfile.path),
filename: original.uploads.blob.filename,
content_type: original.uploads.blob.content_type
})
end
end
end
render 'new'
end