How to update/rename a carrierwave uploaded file?

后端 未结 6 1332
我在风中等你
我在风中等你 2021-02-04 20:30

I cant figure out how to update/rename a file uploaded/managed with Carrierwave-mongoid in rails 3.2.6. I want to rename the file in the db as well as on the filesystem.

<
6条回答
  •  梦毁少年i
    2021-02-04 21:19

    Based on @user892583, I worked on it and came up with a simpler solution:

    def rename!(new_name)
      new_path = File.join(File.dirname(file.file), new_name)
      file.move_to(new_path)
    end
    

提交回复
热议问题