How to update/rename a carrierwave uploaded file?

后端 未结 6 1390
我在风中等你
我在风中等你 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条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 21:12

    I did this with this way:

      def filename
        if !cached? && file.present?
          new_filename = 'foobar'
          new_path = File.join(File.dirname(file.path), new_filename)
          file.move_to(new_path)
          recreate_versions!
          new_filename
        else
          super
        end
      end
    

    I think this is only right way to rename file.

提交回复
热议问题