thoughtbot/paperclip — Issue #743: Paperclip 2.6.0/aws-sdk try to delete styles that don't exist, causing exception
Author: uberllama
Created: 2012-02-16 17:19:11+00:00
State: open

Using Rails 3.2.1 and Ruby 1.9.3.

I was previously running paperclip 2.4.1 with aws-s3 with no issues when deleting a file. Standard asset model, and controller actions for creating and destroying the record.

**asset.rb**
```
has_attached_file :upload,
:styles => {
:tiny => {:geometry => '80x80>', :source_file_options => '-auto-orient'},
:thumb => {:geometry => '480>', :source_file_options => '-auto-orient'},
:large => {:geometry => '1024x1024>', :source_file_options => '-auto-orient'}
}

before_post_process :resize_images

# Resize uploaded asset (i.e. create styles) only if it is an image
def resize_images
return false unless upload_content_type =~ Regex::IMAGE_CONTENT_REGEX
end
```

**assets_controller#create**
```
[paperclip] Saving attachments.
[paperclip] saving attachments/123/original/textfile.rtf
[AWS S3 200 1.153745] put_object(:acl=>:authenticated_read,:bucket_name=>"mydevbucket",:content_disposition=>"attachment",:content_type=>"application/rtf",:data=>#,:key=>"attachments/123/original/textfile.rtf")
```

**assets_controller#destroy**
```

Started DELETE "/attachments/123" for 127.0.0.1 at 2012-02-16 09:57:05 -0700
Processing by AssetsController#destroy as JS
Parameters: {"id"=>"1020"}
Asset Load (0.2ms) SELECT `assets`.* FROM `assets` WHERE `assets`.`id` = 123 LIMIT 1
(0.1ms) BEGIN
[paperclip] Scheduling attachments for deletion.
[AWS S3 200 0.091734] head_object(:bucket_name=>"mydevbucket",:key=>"attachments/123/original/textfile.rtf")

[AWS S3 403 0.093428] head_object(:bucket_name=>"mydevbucket",:key=>"attachments/123/tiny/textfile.rtf") AWS::Errors::Base: AWS::Errors::Base

(0.2ms) ROLLBACK
Completed 500 Internal Server Error in 194ms

AWS::Errors::Base (AWS::Errors::Base):
app/controllers/assets_controller.rb:71:in `destroy'
app/middleware/flash_session_cookie_middleware.rb:18:in `call'

Rendered /Users/yuval/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.2ms)
Rendered /Users/yuval/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.7ms)
Rendered /Users/yuval/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4.4ms)

```

What you'll see here is that the delete request is trying to delete attachments/123/tiny/textfile.rtf, which doesn't exist. _Tiny_ is a style that gets applied to image uploads, along with a few other styles (thumb, etc), as you can see in the asset model.

Enlightenment appreciated.