# Using file\_column and switchtower

**URL:** <https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002>\
**Category:** Rails\
**Created:** [December 11, 2005, 5:38am UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002 "2005-12-11T05:38:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 11, 2005, 5:38am UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002/1 "2005-12-11T05:38:46Z")

</div>

I haven’t actually tried it yet, but I think switchtower conflicts  
somewhat with file\_column.

file\_column puts uploads in the public directory. But when you do a  
‘rake deploy’ with switchtower, then the files that were in the public  
directory aren’t used by the newly released svn export of your site  
(because a new public directory is created).

What’s the easiest way around this issue?

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 11, 2005, 6:03am UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002/2 "2005-12-11T06:03:13Z")

</div>

On 12/10/05, Joe Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks,  
> Joe

Create the upload directory in shared and then an after\_symlink  
callback in switchtower that links it into public/uploads.

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 11, 2005, 6:23am UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002/3 "2005-12-11T06:23:29Z")

</div>

On 12/10/05, Rick O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Create the upload directory in shared and then an after\_symlink  
> callback in switchtower that links it into public/uploads.

So, if files are normally stored in public/training\_event, I’d create  
a directory shared/uploads/training\_event and symlink that to  
public/training\_event?

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 11, 2005, 7:18am UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002/4 "2005-12-11T07:18:29Z")

</div>

On 12/10/05, Rick O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Create the upload directory in shared and then an after\_symlink  
> callback in switchtower that links it into public/uploads.

I have current/public/training\_event symlinked to  
shared/uploads/training\_event.

Here’s the error I get when I try to load anything:

Errno::EEXIST in #

File exists -  
/home/joevd/cisv/current/public/…/config/…/public/training\_event  
RAILS\_ROOT: /home/joevd/cisv/current/public/…/config/…

Application Trace | Framework Trace | Full Trace  
/usr/local/lib/ruby/1.8/fileutils.rb:212:in `mkdir' /usr/local/lib/ruby/1.8/fileutils.rb:212:in `fu\_mkdir’  
/usr/local/lib/ruby/1.8/fileutils.rb:193:in `mkpath' /usr/local/lib/ruby/1.8/fileutils.rb:191:in `reverse\_each’  
/usr/local/lib/ruby/1.8/fileutils.rb:191:in `mkpath' /usr/local/lib/ruby/1.8/fileutils.rb:177:in `each’  
/usr/local/lib/ruby/1.8/fileutils.rb:177:in `mkpath' #{RAILS_ROOT}/vendor/plugins/file_column/lib/file_column.rb:29:in `init\_options’  
#{RAILS\_ROOT}/vendor/plugins/file\_column/lib/file\_column.rb:28:in `each' #{RAILS_ROOT}/vendor/plugins/file_column/lib/file_column.rb:28:in `init\_options’  
#{RAILS\_ROOT}/vendor/plugins/file\_column/lib/file\_column.rb:594:in  
`file_column' #{RAILS_ROOT}/app/models/training_event.rb:11 (eval):5:in `belongs\_to’  
#{RAILS\_ROOT}/app/models/registration.rb:2  
(eval):5:in `has\_many’  
#{RAILS\_ROOT}/app/models/user.rb:13  
#{RAILS\_ROOT}/app/controllers/application.rb:9  
This error occured while loading the following files:  
/home/joevd/cisv/current/public/…/config/…/app/controllers/application.rb  
=\> model user.rb  
user  
registration  
training\_event

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 11, 2005, 3:25pm UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002/5 "2005-12-11T15:25:41Z")

</div>

> I have current/public/training\_event symlinked to shared/uploads/training\_event.
> 
> Here’s the error I get when I try to load anything:
> 
> Errno::EEXIST in #
> 
> File exists - /home/joevd/cisv/current/public/…/config/…/public/training\_event  
> RAILS\_ROOT: /home/joevd/cisv/current/public/…/config/…

hmm, that’s strange, because I’m using FileUtils.mkpath, which creates  
all the directories if they aren’t there already but shouldn’t  
complain if it already exists. I’m wondering if it has troubles with  
the symlinks. Can anybody shed some light on this?

Sebastian

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 11, 2005, 3:33pm UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002/6 "2005-12-11T15:33:39Z")

</div>

On Dec 11, 2005, at 7:23 AM, Sebastian K. wrote:

> > > callback in switchtower that links it into public/uploads.  
> > > RAILS\_ROOT: /home/joevd/cisv/current/public/…/config/…
> 
> hmm, that’s strange, because I’m using FileUtils.mkpath, which creates  
> all the directories if they aren’t there already but shouldn’t  
> complain if it already exists. I’m wondering if it has troubles with  
> the symlinks. Can anybody shed some light on this?

Actually, FileUtils.mkdir\_p will act as you describe. FileUtils.mkdir  
will choke if the path already exists.

- Jamis

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 11, 2005, 6:03am UTC](https://www.ruby-forum.com/t/using-file-column-and-switchtower/53002/7 "2005-12-11T06:03:13Z")

</div>

I store my file\_column database outside of the app path. I also  
include the rails environment in the path. You don’t need to do this,  
but I consider it a best practice.

To include the rails environment in your file\_column path, set the  
following file\_column options:  
:root\_path =\> File.join(RAILS\_ROOT, “public”, RAILS\_ENV),  
:web\_root =\> RAILS\_ENV + “/”

If you want to do this globally, you can patch the source (look for  
“DEFAULT\_OPTIONS”), or you can pass it like: file\_column :field,  
options.

Here’s the gist of my folder structure:

/u/apps/myapp/  
/u/file\_column\_db/myapp/production/

Then, I modifed my deploy.rb file to include the following in the  
restart task (another task may be more appropriate, but this works)

sudo “ln -s /u/file\_column\_db/myapp/production  
/u/apps/myapp/current/public/production”

Of course, you need to set the appropriate permissions on everything…
