How do I rename files uploaded by Paperclip? I have uploaded file /public/system/attachments/15/original/abc.txt
How do I rename abc.txt file into for example xyz.txt ? I know how to update file name attributes of an object, but how to make these changes on the file system?
You need to adapt the:url and :path options from has_attached_file
In this great tutorial (thewebfellas.com) you'll find it all. :)
edit: to just move on disk, after having completed the uploading, you can use FileUtils
#!/usr/bin/env ruby
require 'fileutils'
FileUtils.mv('/your/old/file', '/your/new/file')
Oh and File::rename as well of course.
#!/usr/bin/env ruby
File.rename("afile", "afile.bak")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.