config.fog_directory = "name of my rackspace container"
is in /config/initializers/carrierwave.rb and that's fine because, at the time I wrote the original post I was under the delusion that it was a directory within my container. After all, it knows the url to my container already.
def store_dir
"galleries/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
This is in app/uploaders/photo_uploader.rb
As you can see it emulates AR by placing each photo in a separate directory, in this case rackspace cdn.
The problem here is that, while it ensures that photos are always going to be there, they are really only available from a Rails app and only if the Photo records haven't been deleted.
In my case I have sports leagues, each with their own gallery and so Photo belongs to League. If I delete a League, all its Photo records are deleted by
has_many :photos, :dependent => delete_all
All that's left is each photo in a separate folder on my storage. I would have preferred something like
def store_dir
"galleries/session[:league_id]"
end
The generated uploader rb file contains the following documentation
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
I would have liked to have
def filename
"#{model.id}_#{original_filename}"
end
Being a relative noob here I can only surmise that using session here won't work and that the use of model.id in the filename will cause internal organ failure in carrierwave.
I note that Dragonfly seems to allow dynamic setting of the store path with each save action. The problems I see with Dragonfly are:-
1. It seems to store rack-cache images to a local hard drive anyway, losing any space advantage gained by on the fly processing of a single stored image and using up lots of space on the web server drive instead of a cdn. I am assuming it couldn't cache to a cdn host efficiently.
2. With carrierwave, the person who waits for the image resizing the first time is the uploader, not the downloader.
3. Dragonfly will store the full sized 12 MB image uploaded by some idiot from his pocket canon while carrierwave will resize it to a limit on the way in.
4. Dragonfly resized images are not available to a static site linking directly to the cdn.
For now, I have accepted the carrierwave default store path. The path that I proposed would give me the ability to create a static site linked to photos in a gallery with a known id, particularly useful for archiving photos in an accessible way after the AR photo records have been deleted.