Topic: AllinOneRuby AllinOneHeadache

Hello, I'm using Erik Venkstras tool "AllinoneRuby" to create a rails app. Heres the link to the project: … rails.html

Everything works great for me except that when I shut down my executable, all my data disappears. Now I emailed Erik and he said he explained how to get round it in section 3.4:


Now comes the trickiest part...

Tar2RubyScript transforms your application
(the complete directory tree: program, configuration and
user data) into a single Ruby script, called RBA
(= Ruby archive). When running this RBA, it unpacks itself to a
temporary directory before starting the embedded application.
On termination, this directory is deleted, along with our user data...
That's not what we want! So we have to move the user data to a safe
place before running our application as an RBA.

(In the ideal world, we should "externalize" the logs and some config files as well.)

This means that we have to adjust our code:

C:\rails\demo> notepad config\environment.rb

Add this at the top of the file:

module Rails
  class Configuration
    def database_configuration
      conf = YAML::load(
      if defined?(TAR2RUBYSCRIPT)
        conf.each do |k, v|
          if v["adapter"] =~ /^sqlite/
            v["database"] = oldlocation(v["database"]) if v.include?("database")
            v["dbfile"]   = oldlocation(v["dbfile"])   if v.include?("dbfile")

This overwrites Rails::Configuration#database_configuration, which was originally defined as:

module Rails
  class Configuration
    def database_configuration

What happens? When running an RBA, the programmer
has to deal with two kind of locations: the location
in which the user started the application (accessible
with oldlocation()) and the temporary directory with
the application itself, created by the RBA (accessible
with newlocation()). By using oldlocation() in the code
above, we simply adjust the data from config/database.yml.

Without the adjustment, conf would look like this:

{"development"=>{"database"=>"demo_dev.db", "adapter"=>"sqlite"}
"production"=>{"database"=>"demo_prd.db", "adapter"=>"sqlite"}
"test"=>{"database"=>"demo_tst.db", "adapter"=>"sqlite"}}

With the adjustment, conf would look like this:

{"development"=>{"database"=>"/full/path/to/demo_dev.db", "adapter"=>"sqlite"}
"production"=>{"database"=>"/full/path/to/demo_prd.db", "adapter"=>"sqlite"}
"test"=>{"database"=>"/full/path/to/demo_tst.db", "adapter"=>"sqlite"}}

Can anyone make sense of this? I've tried but I've gotten too many "permission denied" statements. Thanks.

Last edited by daibatzu (2006-07-20 05:37:53)