Rails convert Paperclip directory structure to Carrierwave

限于喜欢 提交于 2019-12-06 15:12:28

The CarrierWave::Compatibility::Paperclip module already provides this functionality. Just do the following in your uploader:

class MyUploader < CarrierWave::Uploader::Base
  include CarrierWave::Compatibility::Paperclip

  # The :id_partition symbol will trigger a proc in the Paperclip compatibility module that will build out the properly partition directory structure
  def store_dir
    "#{model.class.to_s.underscore}/#{mounted_as.to_s}/:id_partition"
  end

end

Have you tried changing the store_dir options define in carrierwave uploader to look exactly like that of paperclip

  def store_dir
    "#{model.class.to_s.underscore}/resume/#{id_partitioning}/original/"
  end

  def id_partitioning
    ("%09d" % model.id).scan(/.{3}/).join("/")
  end

Note : I just done remember how the paperclip does the id_partitioning (how much '0' it pad to the left based on object id )

but based upon your format 000/000/model_id look to me like 9 character Please confirm

Hope this help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!