attachment_fu dances with Capistrano
It is one of these joyous revelations. Today I was having a discussion with a fellow developer on attachment_fu. I am very much a fan of plugins, this means less work for me. In which case I win. He, however, refrained from using attachment_fu. Instead writing his own file upload mechanism. This seemed strange to me and I asked him why. He then correctly pointed out that with attachment_fu he was unable to save files outside his application root directory.
So why is this a problem? Everyone I know is using Capistrano as their preferred way of deploying. The way Capistrano does subsequent deploys is by linking the new release to the current directory and unlinking the old one. Everything in the old release suddenly becomes unavailible! And that includes the files by attachment_fu. And article on Almost Effortless pointed this out several months ago and posted a solution in the form of a Capistrano recipe. But who wants to write their own recipes?
However I seemed to remember seeing a @system@ directory on our live server. And there is! In Capistrano 2.0 every public directory has a link to a system directory which is unaffected by deploys. How well these Capistrano people thought this out. Brilliant. Now it is only a matter of using the :path_prefix argument.
has_attachment :content_type => :image,
:storage => :file_system,
:path_prefix => 'public/system',
:max_size => 500.kilobytes,
:resize_to => '320x200>',
:thumbnails => { :thumb => '100x100>' }
Set svn propset svn:ignore "*" public/system/ and you are ready to go!
April 7th, 2008 at 1:38 pm
Thanks for this!
Want an easy solution
PJ.
May 29th, 2008 at 1:15 am
Does this then break the functionality on development because there is no such “system” directory?
May 29th, 2008 at 8:03 am
I usually create that directory in development and add it to the svn (or git) ignore list. As soon as this directory becomes part of the content of your SCM I do not believe this to still work.