# Using external files in Rails

**URL:** <https://www.ruby-forum.com/t/using-external-files-in-rails/103211>\
**Category:** Rails\
**Created:** [May 3, 2007, 12:02am UTC](https://www.ruby-forum.com/t/using-external-files-in-rails/103211 "2007-05-03T00:02:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![masschel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@masschel](https://www.ruby-forum.com/u/masschel)\
**Post date:** [May 3, 2007, 12:02am UTC](https://www.ruby-forum.com/t/using-external-files-in-rails/103211/1 "2007-05-03T00:02:27Z")

</div>

I’m currently building a dictionary for Flemish Sign Language for the  
the Deaf community in Flanders: [http://patsstudent.cmi.ua.ac.be:8080/](http://patsstudent.cmi.ua.ac.be:8080/)  
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/](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  
computer…  
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  
avoid.  
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/](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!

---

<div class="post-metadata">

**Author:** ![masschel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@masschel](https://www.ruby-forum.com/u/masschel)\
**Post date:** [May 3, 2007, 4:06am UTC](https://www.ruby-forum.com/t/using-external-files-in-rails/103211/2 "2007-05-03T04:06:42Z")

</div>

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 =\> DirHandler.new(‘d:\movies’)

---

<div class="post-metadata">

**Author:** ![masschel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@masschel](https://www.ruby-forum.com/u/masschel)\
**Post date:** [May 4, 2007, 1:01am UTC](https://www.ruby-forum.com/t/using-external-files-in-rails/103211/3 "2007-05-04T01:01:19Z")

</div>

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 =\> DirHandler.new(‘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?  
Thanks,

Bart

---

<div class="post-metadata">

**Author:** ![masschel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@masschel](https://www.ruby-forum.com/u/masschel)\
**Post date:** [May 4, 2007, 1:03pm UTC](https://www.ruby-forum.com/t/using-external-files-in-rails/103211/4 "2007-05-04T13:03:19Z")

</div>

You can read more about mongrel command line options here:  
[http://mongrel.rubyforge.org/docs/howto.html](http://mongrel.rubyforge.org/docs/howto.html)

---

<div class="post-metadata">

**Author:** ![masschel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@masschel](https://www.ruby-forum.com/u/masschel)\
**Post date:** [May 4, 2007, 1:01pm UTC](https://www.ruby-forum.com/t/using-external-files-in-rails/103211/5 "2007-05-04T13:01:18Z")

</div>

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  
it:

:config\_script: config/mongrel.conf

---

<div class="post-metadata">

**Author:** ![masschel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@masschel](https://www.ruby-forum.com/u/masschel)\
**Post date:** [May 4, 2007, 1:08pm UTC](https://www.ruby-forum.com/t/using-external-files-in-rails/103211/6 "2007-05-04T13:08:19Z")

</div>

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?

Bart
