Using external files in Rails

I’m currently building a dictionary for Flemish Sign Language for the
the Deaf community in Flanders:
Besides the internet site I’m building a dvd-version for people who
have no or limited access to internet. Both are the same web
application in Rails, but are deployed slightly different. The
internet site is pretty straight-forward Rails stuff.
The dvd version uses tar2rubyscript and rubyscript2exe so the program
can be executed without installing anything from the dvd. The whole
Rails application is wrapped in one executable, along with Ruby, Rails
and the necessary plugins. Since it’s a dictionary for sign language,
it involves a lot of movie clips that visualize a sign. Those movies
are not included in the executable. That’s the trouble.
When the executable on the dvd is executed, rubyscript2exe unpacks
Ruby, Rails and plugins to a temporary folder (say: “C:\Documents and
Settings\Bart\Local Settings\Temp”). Then tar2rubyscript unpacks the
Rails application, in this case the dictionary, to the temporary
folder. Finally the application is started with WEBrick and I can surf
to http://localhost:3000/.
However, when the application wants to display a movie, the path to
this movie is for example “d:\movies\movie.mpeg”, because it must be
found on the dvd. Most browsers won’t display the movie, for security
issues: suppose an internet site could do stuff with files on your
There is one solution: in Internet Explorer, you can mark “http://
localhost” as a safe website, and the movie will be displayed. But
this is not possible in for example Firefox and it requires the user
of the dvd to change options in the browser, something I would want to
Another theoretic solution would be to put the path through the web
server, so the browser thinks it’s a file on the server itself. The
path would then become something like: “http://localhost:3000/dvd/
movies/movie.mpeg” (or in any case something starting with “http://
localhost:3000/”) and the browser would consider it a safe file.
Is this a possible solution? How can I solve this problem?
Thank you in advance!

The best solution is to have WEBrick serve the movies just like it
would any other file.

In *nix you would just hardlink dvd to your public dvd directory, but
without some weird utilities this isn’t possible in Windows. So you
need to tell WEBrick to serve files from the movies directory on the
DVD as well as the rails public directory. However, without some
monkey patches to the DispatchServlet that comes with rails this is no
easy task.

Would it be possible to include Mongrel in your package? It’s an
alternative to WEBrick that makes it easy to write handlers to serve
files from more than one directory. If you go this route, you can
specify other handlers in a config file that lives in your rails
config directory, eg:

uri “/dvd”, :handler =>‘d:\movies’)

Thank you for your quick reply.
I wanted to try your solution with Mongrel. After some googling, I
discovered that your line of code:
uri “/dvd”, :handler =>‘d:\movies’)
must be in a Mongrel::Configurator block. In this block the app must
be started, I think.
So, how do I merge this uri in my code?


You can read more about mongrel command line options here:

You can get at that part of mongrel startup by providing a file with
that ‘uri …’ line to the -S option on the mongrel_rails start
command line.

I created this file under the config/ directory and called it
mongrel.conf, and I run mongrel like this:

mongrel_rails start -S config/mongrel.conf

Or, if you start mongrel via a config file add the following line to

:config_script: config/mongrel.conf

That works, thanks!
But now another problem raises: when I want to put the application in
a package, I have to provide a file called init.rb that says how to
start the packed program. Basically it says now:
load ‘script/server’
But now i have to let init.rb run the program “mongrel_rails start -S
config/mongrel.conf”. How can I do that?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs