My app (locally) raises ActiveStorage::IntegrityError
error, whenever it tries to attach a file. How can I get out of this error?
I have only one has_one_attached
and I don't know how that error gets in the way.
# model
has_one_attached :it_file
Tempfile.open do |temp_file|
# ...
it_file.attach(io: temp_file, filename: 'filename.csv', content_type: 'text/csv')
end
# storage.yml
local:
service: Disk
root: <%= Rails.root.join("storage") %>
EDIT: it can be related with deleting storage/
directory (it happened after I deleted that) or it can be because it's happening in a job (the full error was Error performing ActivityJob (Job ID: .. ) from Async( .. ) in .. ms: ActiveStorage::IntegrityError (ActiveStorage::IntegrityError)
And this does not add files to storage/
folder but it's generating folders under it when I tried to attach them.
This was happening to me not because of anything mentioned above.
In my case I was defining a test var using one dummy file, but I was attaching it to 2 different records.
The function in question received a list of ids and data and attaching the files to the records. This is a simplified version of the code
Once I defined 2 test vars, one for each record, using the same file I got it to work.