Forum: Ruby on Rails Saving images in shared directory w/ Capistrano/SVN?

Posted by Jeff Coleman (progressions)
on 2006-04-01 06:03
Hi all,

I'm using Capistrano and SVN to version control and deploy, but I'm not 
sure what to do about my images directory.  I use file_column and 
RMagick to save images to the disk under a model called "Image", and 
they're saved in public/image/... etc.

Each time I deploy a new version, my image folder doesn't exist anymore. 
I don't want to version control map my local image folder to the 
server's image folder, so what should I do?

Is it possible to save my images in a shared folder and let Capistrano 
know about that?

Thanks,
Jeff
Posted by Gokhan Arli (sylow)
on 2006-04-01 06:04
Jeff Coleman wrote:
> Hi all,
> 
> I'm using Capistrano and SVN to version control and deploy, but I'm not 
> sure what to do about my images directory.  I use file_column and 
> RMagick to save images to the disk under a model called "Image", and 
> they're saved in public/image/... etc.
> 
> Each time I deploy a new version, my image folder doesn't exist anymore. 
> I don't want to version control map my local image folder to the 
> server's image folder, so what should I do?
> 
> Is it possible to save my images in a shared folder and let Capistrano 
> know about that?
> 
> Thanks,
> Jeff

Yep, use shared folder and write recipie in cap to create sym links from 
public/image
Posted by François Beausoleil (fbeausoleil)
on 2006-04-01 06:37
(Received via mailing list)
2006/3/31, Gokhan Arli <gokhan@sylow.net>:
> Jeff Coleman wrote:
> > Is it possible to save my images in a shared folder and let Capistrano
> > know about that?
>
> Yep, use shared folder and write recipie in cap to create sym links from
> public/image

Make a symlink on the production system and svn add the symlink.
Subversion will notice it is a symlink and will recreate the symlink
on subsequent checkouts.

You need SVN 1.1 or better for this to work.  See
http://svnbook.red-bean.com/nightly/en/svn.advanced.props.html#svn.advanced.props.special.special
for details.

Bye !
Posted by Jeff Coleman (progressions)
on 2006-04-01 06:40
François Beausoleil wrote:
> 2006/3/31, Gokhan Arli <gokhan@sylow.net>:
>> Jeff Coleman wrote:
>> > Is it possible to save my images in a shared folder and let Capistrano
>> > know about that?
>>
>> Yep, use shared folder and write recipie in cap to create sym links from
>> public/image
> 
> Make a symlink on the production system and svn add the symlink.
> Subversion will notice it is a symlink and will recreate the symlink
> on subsequent checkouts.
> 
> You need SVN 1.1 or better for this to work.  See
> http://svnbook.red-bean.com/nightly/en/svn.advanced.props.html#svn.advanced.props.special.special
> for details.
> 
> Bye !

Wow, that is nice.  I went ahead and made a cap recipe to recreate the 
symlink, but that's pretty much seamless.  Thanks!

Jeff
Posted by Kyle Maxwell (Guest)
on 2006-04-01 23:22
(Received via mailing list)
I just blogged this:
http://kylemaxwell.com/articles/2006/04/01/using-filecolumn-with-capistrano

---------

I assume that you already have basic familiarity iwth Ruby, Rails, the
Rails plugin system, Capistrano, and FileColumn (or file_column), but
not neccessarily the internals of the above programs.

Let's get them all working together.

First, for convienience, you should choose the name of a folder in
your site for the file_column content to reside. I usually set this to
RAILS_ENV, so that I can run with multiple environments on one rails
app. Your file_column content is tied to a specific database, and if
multiple environments use the same folder, then you have the potential
to overwrite data.

Ok, so you've chosen your folder name. I'll assume you've stuck to my
convention of www.yoursite.com/RAILS_ENV/, but you can choose a
prettier name if you'd like. We're going to make file_column
understand this preference in one of two ways:

1. Call file_column with options:

file_column :some_image,
  :root_path => File.join(RAILS_ROOT, "public", RAILS_ENV),
  :web_root => RAILS_ENV + "/"

The problem with this is that its not very DRY. To make it DRY, you 
should:

2. Modify the DEFAULT_OPTIONS hash directly, in
vendor/plugins/file_column/lib/file_column.rb, around line 500 or so.

Now you've got to make Capistrano symlink this folder into another
folder in your shared directory. To do this, add the following to your
deploy.rb recipe. Then run `cap setup`

task :after_setup
  run "mkdir #{shared_path}/production"
end

task :after_symlink do
  run "ln -nfs #{shared_path}/production 
#{release_path}/public/production"
end

--
Kyle Maxwell
Chief Technologist
E Factor Media // FN Interactive
kyle@efactormedia.com
1-866-263-3261
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.