3

Is there a way to rename files after upload? I want files to match model id after it is saved:

# image.rb

after_create :rename_file

def rename_file
  file.rename!(id)
end

But I can't find a simple way to do this.

Update The method file.move_to was in Carrierwave 0.9.0 but was removed since.

firedev
  • 20,898
  • 20
  • 64
  • 94
  • have you read this wiki [How to: Create random and unique filenames for all versioned files](https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Create-random-and-unique-filenames-for-all-versioned-files) ? – rails_id Jun 06 '14 at 04:25
  • Read this : http://stackoverflow.com/questions/12964255/how-to-update-rename-a-carrierwave-uploaded-file – Emu Jun 06 '14 at 04:26
  • I have tried this, it doesn't work, I guess Carrierwave has change since. And I don't want random and unique filenames. After the image is saved I do know it's ID. All I need is to rename generated files and update the filename in the model. – firedev Jun 06 '14 at 10:38
  • @firedev you find any solution – Haseeb Ahmad Jun 20 '18 at 16:32

0 Answers0