thoughtbot/paperclip — comment on commit 7a8d1e639c4ec04736557e129dc46ebd66dbbdfc
File: lib/paperclip/storage/s3.rb line 102
By m4n:

I have the following use case for the new `:s3_headers` can be set as a Proc feature. Given the following models

```
class Band < ActiveRecord::Base
has_many :songs
attr_accessible :name
end

class Song < ActiveRecord::Base
belongs_to :band
attr_accessible :title, :audio
has_attached_file :audio, :storage => :s3, :s3_credentials => ...,
:s3_headers => Proc.new { |song| { 'Content-Disposition' => "attachment; filename=\"#{song.download_filename}\"" } }

def download_filename
"#{artist.name} - #{song.title}.mp3"
end
end
```

When I create a new song like this

```
band = Band.first
band.songs.create! :title => "Test", :audio => open("test.mp3")
```

it fails with `NoMethodError: undefined method 'name' for nil:NilClass` in `Song#download_filename` because the `artist` association is not set at the time the Proc gets called by Paperclip.

In order to fix this, I would like to recommend calling the Proc at a later time. Maybe in the `flush_writes` method?