jnicklas/carrierwave — Issue #508: Issues with displaying and removing directory versioned images
Author: rybon
Created: 2011-10-27 23:02:23+00:00
State: open

I've come across several issues getting CarrierWave configured to my preferences. Everything works fine when I stick to the defaults, but I want to customize the way images are stored, by using the following settings:

```ruby
class ImageUploader < CarrierWave::Uploader::Base

include CarrierWave::RMagick

storage :file

def store_dir
"uploads/#{model.class.to_s.underscore}/#{model.id}/#{version_name}"
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def default_url
"/images/fallback/no-img.png"
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
end

version :small do
process :resize_to_fill => [220, 165]
def full_filename for_file = model.image.file
original_filename
end
end

version :medium do
process :resize_to_fill => [300, 225]
def full_filename for_file = model.image.file
original_filename
end
end

version :large do
process :resize_to_fill => [640, 480]
def full_filename for_file = model.image.file
original_filename
end
end

def extension_white_list
%w(jpg jpeg gif png)
end

def filename
original_filename
end
end
```

Storing an image this way works fine; I get a structure like this (Image is the model I've mounted the Uploader):

* public/uploads/image/13/some-file.jpg
* public/uploads/image/13/small/some-file.jpg
* public/uploads/image/13/medium/some-file.jpg
* public/uploads/image/13/large/some-file.jpg

The first issue is when I try to display an image in the view:

```ruby
image.image_url(:small) # returns 'public/uploads/image/13/small' instead of the expected 'public/uploads/image/13/small/some-file.jpg'
```

I solved this, but it feels messy:

```ruby
image.image_url(:small) + '/' + image.image_identifier
```

The second issue is when I try to remove an image. The original file _'public/uploads/image/13/some-file.jpg'_ is removed successfully, but the versioned ones are not. Instead I get the following error:

> Errno::EISDIR
> Is a directory - public/uploads/image/13/small

It seems to be the same problem as in the view; the code returns a directory and forgets to append the filename. I tried to use the _:remove_ callback to get around this problem, but to no avail.

Are these issues due to problems in my code or in CarrierWave itself?