0

I'm trying to setup the store_dir for the files being uploaded to carrier wave, but I want a particular url structure (like I had using paperclip). I have two versions :main and :thumb, but it seems that the url being store using model.id is /MODEl/ID/VERSION_IMAGENAME.FILETYPE. I am trying to figure out how to structure the url to be /MODEL/ID/VERSION/IMAGENAME.FILETYPE, but am not having any luck. Any help?

A sample url:

/event/1/main_IMG1922.JPG, but I would like to have /event/1/main/IMG1922.JPG.

Thanks!

DevanB
  • 377
  • 1
  • 6
  • 16

1 Answers1

0

You can probably do this overriding the full_filename and full_original_filename methods as shown on this carrierwave wiki page

Here's the example they show for changing filenames from version_foo.jpg to foo_version.jpg. Customize it to suit your needs.

module CarrierWave
  module Uploader
    module Versions
      def full_filename(for_file)
        parent_name = super(for_file)
        ext         = File.extname(parent_name)
        base_name   = parent_name.chomp(ext)
        [base_name, version_name].compact.join('_') + ext
      end

      def full_original_filename
        parent_name = super
        ext         = File.extname(parent_name)
        base_name   = parent_name.chomp(ext)
        [base_name, version_name].compact.join('_') + ext
      end
    end
  end
end
Dty
  • 12,253
  • 6
  • 43
  • 61
  • Would I create that file in an initializer. I can see making it work, but the wiki doesn't specify the file name or location to put a file that overwrites those methods. – DevanB Jul 08 '13 at 19:04
  • WHERE to put files for monkey patching is debatable. But it should work in an initializer. Here's a related SO question/answer http://stackoverflow.com/questions/3420680/monkey-patching-in-rails-3 – Dty Jul 08 '13 at 22:37