Reputation: 3741
I'm using refile
gem to upload files to S3
and having the following model
class DataFile < ActiveRecord::Base
attachment :document, destroy: true
end
The respective table in database has columns document_filename
and document_id
to hold file metadata.
I need to remove file from S3
and keep the respective row in DB (I need that to be able to display the name and delete date of that file).
I'm trying to do
data_file.document = nil
data_file.save()
But that removes filename. Is there a solution to remove file from S3 and keep document_filename
value.
Upvotes: 0
Views: 120
Reputation: 121010
I would go with defining 2 new columns in the respective model and copying the data to remain there upon removal.
This is way more consistent than keeping the malformed refile
objects:
data_file.update_attributes!(
file_name: data_file.document.filename,
removed_at: DateTime.now,
document: nil)
Upvotes: 1