Rafael Oliveira
Rafael Oliveira

Reputation: 2923

Carrierwave - Uniqueness of original_filename

When does Carrierwave save the model is mounted on?

Is it after uploading to AWS or before?

I would like to know because I'm saving the original_filename and making it Unique at my model, but this isnt ensuring uniqueness of the original_filename.

If two requests, with same filename, are sent at the sametime, I will get both records on my DB.

Gist: https://gist.github.com/rafaelcgo/87cf7a0651e40a02af9e

Upvotes: 0

Views: 116

Answers (1)

Taavo
Taavo

Reputation: 2414

Carrierwave stores the file after saving the record. Note that this is before committing the save, so it's still possible to rollback the save if something goes wrong during store.

Your problem may be in validates_uniqueness_of. It doesn't work across transactions. See here (19:16), and here.

Upvotes: 1

Related Questions