Rails convert Paperclip directory structure to Carrierwave

I was using the Paperclip gem: https://github.com/thoughtbot/paperclip

I'm now using Carrierwave: https://github.com/carrierwaveuploader/carrierwave

My production website is currently using Paperclip. I'm going to be updating the production website to use Carrierwave.

The folder structure for uploads in Paperclip differs from Carrierwave.

I'm also using Amazon S3 to store uploads.

I'm wondering if there's a way to convert my production files uploaded with Paperclip to Carrierwave.

For example, with Paperclip in production I currently have something like the following for resumes:

bucket_name/model_name/resume/000/000/model_id/original/test.pdf

With Carrierwave it should be:

bucket_name/uploads/model_name/resume/model_id/original/test.pdf

Right now it seems I have to make this conversion manually. I was wondering if there's a better approach.

Please advise.

Answers


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


Need Your Help

Delete multiple rows based on some constrains

r dataframe filtering delete-row

I'm using R and I am trying to delete some rows from a data frame based on some constrains. so, if I got