I am using latest rails and ruby for a new project, I am using Active Storage
for upload files ( images and videos ) to GCP
, when I upload multiples files about 13-18 images, it takes too long to upload and when I check on my database after it finished, my record_id
is 0
? is there something wrong?
class Gallery < ApplicationRecord
has_many_attached :files
end
my gallery id is UUID for the primary key is this caused by this? because on their documentations said
If you are using UUIDs instead of integers as the primary key on your models
you will need to change the column type of "record_id"
for the active_storage_attachments table in the generated migration accordingly.
I ran into this as well:
It is because the record_id column is of type integer. When you try to enter a uuid into it the following happens and you get the record_id 0
for most attachments:
2.7.0 :001 > "a2".to_i
=> 0
2.7.0 :002 > "2a".to_i
=> 2
In the migration that is created when you set up ActiveStorage there is a line that looks like this:
t.references :record, null: false, polymorphic: true, index: false
For use with UUIDs you'll have to add type: :uuid
in order to set the type of the foreign key explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With