# File\_column :root\_path question

**URL:** <https://www.ruby-forum.com/t/file-column-root-path-question/52694>\
**Category:** Rails\
**Created:** [January 18, 2006, 1:22am UTC](https://www.ruby-forum.com/t/file-column-root-path-question/52694 "2006-01-18T01:22:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hatless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/848f3c/32.png) [@hatless](https://www.ruby-forum.com/u/hatless)\
**Post date:** [January 18, 2006, 1:22am UTC](https://www.ruby-forum.com/t/file-column-root-path-question/52694/1 "2006-01-18T01:22:05Z")

</div>

I’m developing on Windows and deploying to FreeBSD+lighttpd using  
Switchtower and I’ve got things generally working. My problem now is  
that file\_column data gets zapped every time I deploy, because  
Switchtower creates a whole new myapp/public directory with each rev.

I looked through the file\_column docs and found the :root\_path option,  
which I use in my models as follows:

class Foo \< ActiveRecord::Base  
if RAILS\_ENV == ‘production’ then  
file\_column :image, {:root\_path =\>  
“/home/www/rails-apps/myapp-externals” }  
else  
file\_column :image  
end  
end

This is kludgy and I don’t like hard-coding a path, but this at least  
gets file\_column to store files outside my application’s root.

As far as uploading files goes, this is working fine. But  
url\_to\_file\_column still generates URIs that point to the directory  
tree under myapp/public so of course my files aren’t available to the  
browser.

How do I gracefully and maintainably fix this? It’s not simply a matter  
of a redirect in my lighttpd.conf since the url\_for\_file\_column uris  
have paths that share namespace with controllers. The thought of making  
an explicit redirect for every file\_column-managed field seems  
un-Rails-like in the extreme.

Any thoughts on how to do this in a way that won’t require changes to  
lighttpd.conf every time I add or change a file\_column field in my  
schema?

Thanks.

-sk

---

<div class="post-metadata">

**Author:** ![hatless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/848f3c/32.png) [@hatless](https://www.ruby-forum.com/u/hatless)\
**Post date:** [January 18, 2006, 3:10am UTC](https://www.ruby-forum.com/t/file-column-root-path-question/52694/2 "2006-01-18T03:10:10Z")

</div>

On 1/17/06, Steve K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> file_column :image, {:root_path =>
> 
> ```
> 
> As far as uploading files goes, this is working fine. But  
> url\_to\_file\_column still generates URIs that point to the directory  
> tree under myapp/public so of course my files aren’t available to the  
> browser.

Looking in the source there is another config option, :web\_root. Have  
you tried using that in conjuction with :root\_path? I’m still reading  
the source to see exactly what it does, there is no doc for it but it  
is listed as a config option.

```
# default options. You can override these with +file_column+'s

```

+options+ parameter  
DEFAULT\_OPTIONS = {  
:root\_path =\> File.join(RAILS\_ROOT, “public”),  
:web\_root =\> “”,  
:mime\_extensions =\> MIME\_EXTENSIONS,  
:extensions =\> EXTENSIONS,  
:fix\_file\_extensions =\> true,  
:permissions =\> 0644,

```
  # path to the unix "file" executbale for
  # guessing the content-type of files
  :file_exec => "file"
}.freeze

```

> 

–  
Jon S.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![hatless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/848f3c/32.png) [@hatless](https://www.ruby-forum.com/u/hatless)\
**Post date:** [January 18, 2006, 10:35am UTC](https://www.ruby-forum.com/t/file-column-root-path-question/52694/3 "2006-01-18T10:35:55Z")

</div>

Hi Steve,

On 1/18/06, Steve K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> file_column :image, {:root_path =>
> 
> ```
> 
> As far as uploading files goes, this is working fine. But  
> url\_to\_file\_column still generates URIs that point to the directory  
> tree under myapp/public so of course my files aren’t available to the  
> browser.

As Jon already mentioned, you could use the “:web\_root” option. Set it  
to the relative URL that is needed to reach the path you gave as  
:root\_path. Another possibility is to use a symbolic link that points  
into your shared directory (same as for public/system). You can even  
extend your switchtower recipes to automate creation of these links.  
The switchtower docs will tell you more about how this can be done.

As far as I remember, there was a thread on this mailing list as well,  
that covered, how to integrate file\_column with switchtower.

Sebastian

---

<div class="post-metadata">

**Author:** ![hatless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/848f3c/32.png) [@hatless](https://www.ruby-forum.com/u/hatless)\
**Post date:** [January 18, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/file-column-root-path-question/52694/4 "2006-01-18T17:59:06Z")

</div>

Sebastian K. wrote:

> As Jon already mentioned, you could use the “:web\_root” option. Set it  
> to the relative URL that is needed to reach the path you gave as  
> :root\_path. Another possibility is to use a symbolic link that points  
> into your shared directory (same as for public/system). You can even  
> extend your switchtower recipes to automate creation of these links.  
> The switchtower docs will tell you more about how this can be done.
> 
> As far as I remember, there was a thread on this mailing list as well,  
> that covered, how to integrate file\_column with switchtower.
> 
> Sebastian

Thanks, guys. I ended up using

1. :root\_path on each of my file\_column declarations in my models to  
specify the absolute path to the directory where I want the production  
server to put file\_column files

2. :web\_root on each file\_column model declaration to assign a URI  
prefix (“ext/” in this case), and then

3. an alias in my lighttpd.conf pointing requests for the prefix to the  
absolute path.

In order to allow development to continue smoothly on Win32 with a  
different directory tree, the :web\_root and :root\_path only get set in  
the production environment.

I suppose it would be better to express the conditionals in the  
environment files, but it’s working for the moment.

I will probably take Sebastian’s suggestion and change things to use a  
symlink created by switchtower rather than a lighttpd.conf alias  
directive to allow the server to get to the files outside the docroot.  
The more that can be handled within rails rather than the webserver, the  
better.

Given the momentum behind Switchtower, I think it would be a good idea  
to create a standard location for asset directories that maybe get  
auto-generated alongside an application’s RAILS\_ROOT during development,  
and get generated empty as needed via Switchtower, but are not part of  
the tree managed by SCM. Not sure how that would work. Or if that’s too  
complex given different dev and prod evvironments, there should at least  
be a standard configuration directive for the production environemt that  
contains an application-wide external asset path instead of sticking  
things in public/.

Nu?

-sk
