Skip to content

Instantly share code, notes, and snippets.

@pithyless
Created October 4, 2011 15:18
Show Gist options
  • Save pithyless/1261919 to your computer and use it in GitHub Desktop.
Save pithyless/1261919 to your computer and use it in GitHub Desktop.
Carrierwave custom store_path

Carrierwave recommends overriding store_dir in the uploader, but it only gives you a way to modify the directory name, not the whole path with the file name. Overriding store_path let's you modify the entire path.

def store_path(for_file = filename)
  self.model.class.name.underscore.pluralize + "/" + self.model.slug + "/" + (version_name || :original).to_s + ".jpg"
end

This is the original:

def store_path(for_file=filename)
  File.join([store_dir, full_filename(for_file)].compact)
end
@pithyless
Copy link
Author

Correct. It's been a while, but looking back at this, my version should be using File.join, not + "/". Although that's neither here, nor there.

@denysonique you should definitely look at the existing carrierwave source (eg. compare store_path to the one above). In six months, a lot may have changed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment