Route to static folder (to browse files)

2,094 views
Skip to first unread message

sa 125

unread,
Jul 22, 2009, 5:47:47 AM7/22/09
to rubyonra...@googlegroups.com
Hi -

I want to enable access to a directory inside my app's public folder.
This means that when a user will navigate to http://myapp.com/files, he
will actually be accessing the root of RAILS_ROOT/public/files. This
folder will contain static files, and doesn't really need any
controller/actions - mostly to be used as a static file server (js, css)
for another app.

I'm trying to accomplish that through the routes.rb file, but so far w/o
success. Is it possible?

Thanks!
--
Posted via http://www.ruby-forum.com/.

Gustav Paul

unread,
Jul 22, 2009, 6:16:32 AM7/22/09
to rubyonra...@googlegroups.com
Hey,

That shouldn't need any modification to your routes. Unless you have a very peculiar setup, files from your ./public/ directory are automatically served as static.

RAILS_ROOT/public/files/some_file.pdf

Should be accessible as:

http://myapp.com/files/some_file.pdf

Regards,
Gustav Paul

sa 125

unread,
Jul 22, 2009, 9:26:15 AM7/22/09
to rubyonra...@googlegroups.com
Gustav Paul wrote:

> That shouldn't need any modification to your routes. Unless you have a
> very
> peculiar setup, files from your ./public/ directory are automatically
> served
> as static.
>
> RAILS_ROOT/public/files/some_file.pdf
>
> Should be accessible as:
>
> http://myapp.com/files/some_file.pdf

Gustav - you're right, I was taking a long detour instead of the direct
rout (pun intended). Thanks!

Zach Karpinski

unread,
Jul 22, 2009, 9:43:44 AM7/22/09
to Ruby on Rails: Talk
One additional note here for Apache users: it is pretty standard to
turn off the "browsing" feature on directories. If your virtual host
configuration allows for it you can override this option on a per
directory basis with .htaccess files.

To enable:
Options Indexes

To disable:
Options -Indexes
Reply all
Reply to author
Forward
0 new messages