SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
Distributing Rails Applications - A Tutorial
Table of Contents
Distributing Rails Applications............................................................................................................1
       A Tutorial ...................................................................................................................................1
                 .

1. Introduction........................................................................................................................................2

2. Ingredients..........................................................................................................................................3
        2.1. Ruby.....................................................................................................................................3
        2.2. Rails.....................................................................................................................................3
        2.3. SQLite..................................................................................................................................3
        2.4. Ruby-SQLite Bindings........................................................................................................3
        2.5. Tar2RubyScript ...................................................................................................................3
                                    .
        2.6. RubyScript2Exe...................................................................................................................3

3. The Steps.............................................................................................................................................5
        3.1. Setup the Environment........................................................................................................5
                                                .
        3.2. Create the SQLite Database.................................................................................................5
        3.3. Develop the Rails Application.............................................................................................5
        3.4. Create the RBA from the Application with Tar2RubyScript..............................................6
        3.5. Create the standalone Executable with RubyScript2Exe                                   .....................................................8

4. Conclusion..........................................................................................................................................9




Distributing Rails Applications - A Tutorial                                                                                                            i
Distributing Rails Applications
                                A Tutorial
                          Sun Dec 24 19:01:32 UTC 2006
                         Erik Veenstra <erikveen@dds.nl>




Distributing Rails Applications - A Tutorial               1
1. Introduction
(Before we start: On real production servers, don't "deploy" a Rails application like this. That's not a good idea. But if you only want to ship
your demo, well, read on...)


I get a lot of emails about packing and distributing Rails applications with Tar2RubyScript and
RubyScript2Exe. It obviously wasn't easy to come up with the steps that have to be taken to transform
a Rails application into a standalone application. Since I never built a Rails application myself, I
wasn't even sure if it was possible at all. That's why I decided to write this tutorial.

In this tutorial, we'll go through the following steps:

        1. Setup the environment
        2. Create the SQLite database
        3. Develop the Rails application
        4. Create the RBA (= Ruby archive) from the application with Tar2RubyScript
        5. Create the standalone executable with RubyScript2Exe

Before we begin, I assume that you've installed the following components (The version numbers are
the versions I've installed myself.):

         • Ruby (1.8.2)
         • Rails (0.14.3)
         • SQLite (2.8.15)
         • Ruby-SQLite bindings (2.2.3)

Since a lot of information about the installation of each individual component can be found on the
'Net, I skip the do-this-to-install-that part. Well, we have to start somewhere...

For this tutorial, I used the RubyInstaller version of Ruby on Windows 2000 and installed both Rails
and SQLite-Ruby with RubyGems. But you could use Linux as well. Every single step is the same on
both platforms. The differences are just textual: back slashes instead of forward slashes, c:> instead
of # and copy instead of cp. That's it.

More general information about distributing Ruby applications (especially Tar2RubyScript,
RubyScript and how they work together) can be found here.




Distributing Rails Applications - A Tutorial                                                                                                       2
2. Ingredients
2.1. Ruby
Ruby is "the interpreted scripting language for quick and easy object-oriented programming. It has
many features to process text files and to do system management tasks (as in Perl). It is simple,
straight-forward, extensible, and portable".

See the Ruby site for more information about Ruby.

2.2. Rails
Rails is "a full-stack, open-source web framework in Ruby for writing real-world applications with
joy and less code than most frameworks spend doing XML sit-ups".

See the Rails site for more information about Rails.

2.3. SQLite
SQLite is "a self-contained, embeddable, zero-configuration SQL database engine".

See the SQLite site for more information about SQLite.

2.4. Ruby-SQLite Bindings
Ruby-SQLite "allows Ruby programs to interface with the SQLite database engine".

See the SQLite-Ruby site for more information about SQLite-Ruby.

2.5. Tar2RubyScript
Tar2RubyScript "transforms a directory tree, containing your application, into one single Ruby
script, along with some code to handle this archive. This script can be distributed to our friends.
When they've installed Ruby, they just have to double click on it and your application is up and
running!"

See the Tar2RubyScript site for more information about Tar2RubyScript.

This is all you need: tar2rubyscript.rb. A "gem install tar2rubyscript" will do,
too.

2.6. RubyScript2Exe
RubyScript2Exe "transforms your Ruby script into a standalone, compressed Windows, Linux or Mac
OS X (Darwin) executable. You can look at it as a "compiler". Not in the sense of a

Distributing Rails Applications - A Tutorial                                                          3
2. Ingredients

source-code-to-byte-code compiler, but as a "collector", for it collects all necessary files to run your
script on an other machine: the Ruby script, the Ruby interpreter and the Ruby runtime library
(stripped down for this script). Anyway, the result is the same: a standalone executable
(application.exe). And that's what we want!"

See the RubyScript2Exe site for more information about RubyScript2Exe.

This is all you need: rubyscript2exe.rb. A "gem install rubyscript2exe" will do,
too.




Distributing Rails Applications - A Tutorial                                                               4
3. The Steps
3.1. Setup the Environment
First of all, create a simple Rails application and test it:

C:rails> rails demo
C:rails> cd demo
C:railsdemo> ruby scriptserver

Point your browser to http://localhost:3000/.

3.2. Create the SQLite Database
Now let's create a test database:

With Ruby:

C:railsdemo> ruby
require "rubygems"
require_gem "sqlite-ruby"
SQLite::Database.new("demo_dev.db").execute(
"create table books (id integer primary key,                   
                      title varchar(255),                      
                      author varchar(255));")
^D # That's ctrl-D...

Or with SQLite:

C:railsdemo> sqlite demo_dev.db
SQLite version 2.8.15
Enter ".help" for instructions
sqlite> create table books
   ...> (id integer primary key,
   ...> title varchar(255),
   ...> author varchar(255)
   ...> );
sqlite> .quit

And copy this empty database to a test database and a production database, for later usage:

C:railsdemo> copy demo_dev.db demo_tst.db
C:railsdemo> copy demo_dev.db demo_prd.db


3.3. Develop the Rails Application
Configure the application to use SQLite:

C:railsdemo> notepad configdatabase.yml

Replace the contents of this file with something like this:

Distributing Rails Applications - A Tutorial                                                  5
3. The Steps
development:
  adapter: sqlite
  database: demo_dev.db

test:
  adapter: sqlite
  database: demo_tst.db

production:
  adapter: sqlite
  database: demo_prd.db

Create the model and the controller:

C:railsdemo> ruby scriptgenerate model Book
C:railsdemo> ruby scriptgenerate controller Book
C:railsdemo> notepad appcontrollersbook_controller.rb

Edit this file, so it looks like this:

class BookController < ApplicationController
  scaffold :book
end

Test it:

C:railsdemo> ruby scriptserver

Point your browser to http://localhost:3000/book/list and add some new books.

3.4. Create the RBA from the Application with
Tar2RubyScript
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:railsdemo> notepad configenvironment.rb

Add this at the top of the file:

module Rails
  class Configuration
    def database_configuration
      conf = YAML::load(ERB.new(IO.read(database_configuration_file)).result)

Distributing Rails Applications - A Tutorial                                                         6
3. The Steps
      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")
           end
        end
      end
      conf
    end
  end
end

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

module Rails
  class Configuration
    def database_configuration
      YAML::load(ERB.new(IO.read(database_configuration_file)).result)
    end
  end
end

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"}}

Tar2RubyScript also needs init.rb, which is the entry point. So we create it:

C:railsdemo> notepad init.rb

It looks like this:

at_exit do
  require "irb"
  require "drb/acl"
  require "sqlite"
end

load "script/server"


Distributing Rails Applications - A Tutorial                                                    7
3. The Steps

The require's are a little trick. If you start and stop a Rails application, without any interaction with
a browser, not all require's of the program are encountered, so RubyScript2Exe might miss some
libraries. Requiring them at the end avoids this problem. It's just bad behavior (in casu of Rails...) to
require some libraries halfway a program...

Now it's time to pack the application into an RBA:

C:railsdemo> cd ..
C:rails> ruby tar2rubyscript.rb demo

Tar2RubyScript creates demo.rb, which is the RBA. This RBA contains both the application and
the databases. But we're not going to use this embedded user data (do you remember
oldlocation?), so we copy the DB's to the current directory:

C:rails> copy demo*.db

Now we can test our RBA:

C:rails> ruby demo.rb [-e environment]

Once again: the DB's we use when running as RBA are not the same as the DB's we use when running
the application the old way! The sets are simply in another directory.

3.5. Create the standalone Executable with
RubyScript2Exe
Creating a standalone executable is as simple as this:

C:rails> ruby rubyscript2exe.rb demo.rb
^C (When Rails is started...) # That's ctrl-C...

RubyScript2Exe creates demo.exe (or demo_linux or demo_darwin, depending on your
platform).

Now we copy demo.exe and demo_*.db to our USB memory stick, drive to our customer (he
hasn't Ruby...) and simply start the application:

C:rails> demo.exe [-e environment]




Distributing Rails Applications - A Tutorial                                                           8
4. Conclusion
No installation of Ruby, no installation of RubyGems, no installation of the various gems, no
installation of SQLite; There's only one executable!

Another conclusion concerns Rails. Rails has two architectural shortcomings (related to distributing
the application):

        • The user data isn't separated from the application itself.
        • require is used halfway the program. This is not RubyScript2Exe-friendly.

As we've seen, both shortcomings can be worked around.

          aior all allinone allinoneruby applications archive bin browser code codesnippet codesnippets compile compiler computer
      computerlanguage dialog dialogs distribute distributing distributingrubyapplications distribution eee eee-file eeefile erik erikveen
 erikveenstra exe executable exerb file graphical graphicaluserinterface gui gz html http httpserver iloveruby interface jar jit just justintime
lang language one pack package packaging packing packingrubyapplications programming programminglanguage rar rb rb2bin rb2exe rba
  rbarchive rbtobin rbtoexe rbw ruby ruby2bin ruby2exe rubyapplications rubyarchive rubycompiler rubyscript rubyscript2 rubyscript2exe
rubyscripts rubyscripttoexe rubytobin rubytoexe rubyweb rubywebdialog rubywebdialogs script scripts server snippet snippets t2rb t2rs tar
 tar2rb tar2rbscript tar2rs tar2rscript time ui user userinterface veenstra web webbrowser webdialog webdialogs window windowinbrowser
                                                           windows wrap wrapper wxruby zip




Distributing Rails Applications - A Tutorial                                                                                                       9

Weitere ähnliche Inhalte

Was ist angesagt?

Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Yevgeniy Brikman
 
Why we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.ukWhy we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.ukGraham Tackley
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and ActivatorKevin Webber
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSPGary Yeh
 
Installaling Puppet Master and Agent
Installaling Puppet Master and AgentInstallaling Puppet Master and Agent
Installaling Puppet Master and AgentRanjit Avasarala
 
Introducing Chef | An IT automation for speed and awesomeness
Introducing Chef | An IT automation for speed and awesomenessIntroducing Chef | An IT automation for speed and awesomeness
Introducing Chef | An IT automation for speed and awesomenessRamit Surana
 
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...Codemotion
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsLukasz Lysik
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionMazenetsolution
 
Managing big test environment and running tests with Jenkins, Jenkins Job bui...
Managing big test environment and running tests with Jenkins, Jenkins Job bui...Managing big test environment and running tests with Jenkins, Jenkins Job bui...
Managing big test environment and running tests with Jenkins, Jenkins Job bui...Timofey Turenko
 
Introduction to Play Framework
Introduction to Play FrameworkIntroduction to Play Framework
Introduction to Play FrameworkWarren Zhou
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Saeed Zarinfam
 

Was ist angesagt? (20)

Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
 
Why we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.ukWhy we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.uk
 
Play framework
Play frameworkPlay framework
Play framework
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Servlets
ServletsServlets
Servlets
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Docker toolbox
Docker toolboxDocker toolbox
Docker toolbox
 
Installaling Puppet Master and Agent
Installaling Puppet Master and AgentInstallaling Puppet Master and Agent
Installaling Puppet Master and Agent
 
Introducing Chef | An IT automation for speed and awesomeness
Introducing Chef | An IT automation for speed and awesomenessIntroducing Chef | An IT automation for speed and awesomeness
Introducing Chef | An IT automation for speed and awesomeness
 
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
Gianluca Arbezzano Wordpress: gestione delle installazioni e scalabilità con ...
 
Rails Security
Rails SecurityRails Security
Rails Security
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Servlet 01
Servlet 01Servlet 01
Servlet 01
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
 
Managing big test environment and running tests with Jenkins, Jenkins Job bui...
Managing big test environment and running tests with Jenkins, Jenkins Job bui...Managing big test environment and running tests with Jenkins, Jenkins Job bui...
Managing big test environment and running tests with Jenkins, Jenkins Job bui...
 
Introduction to Play Framework
Introduction to Play FrameworkIntroduction to Play Framework
Introduction to Play Framework
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
 

Andere mochten auch

M Y S P I R I T U A L Q U E S T O N D R
M Y  S P I R I T U A L  Q U E S T O N   D RM Y  S P I R I T U A L  Q U E S T O N   D R
M Y S P I R I T U A L Q U E S T O N D Rdrsolapurkar
 
Informing Faculty Case Template
Informing Faculty Case TemplateInforming Faculty Case Template
Informing Faculty Case Templatetutorialsruby
 
An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203
An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203
An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203tutorialsruby
 

Andere mochten auch (6)

M Y S P I R I T U A L Q U E S T O N D R
M Y  S P I R I T U A L  Q U E S T O N   D RM Y  S P I R I T U A L  Q U E S T O N   D R
M Y S P I R I T U A L Q U E S T O N D R
 
p10
p10p10
p10
 
Informing Faculty Case Template
Informing Faculty Case TemplateInforming Faculty Case Template
Informing Faculty Case Template
 
FreshAir2008
FreshAir2008FreshAir2008
FreshAir2008
 
An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203
An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203
An%20Intermediate%20Google%20SketchUp%20Tutorial%20-%20Part%203
 
M.S.Transcript
M.S.TranscriptM.S.Transcript
M.S.Transcript
 

Ähnlich wie Distribute Rails Apps as Standalone Executables

Rails
RailsRails
RailsSHC
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on RailsViridians
 
Building Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkBuilding Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkEdureka!
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Railsanides
 
Building Application With Ruby On Rails Framework
Building Application With Ruby On Rails FrameworkBuilding Application With Ruby On Rails Framework
Building Application With Ruby On Rails FrameworkVineet Chaturvedi
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction Tran Hung
 
All girlhacknight intro to rails
All girlhacknight intro to railsAll girlhacknight intro to rails
All girlhacknight intro to railsNola Stowe
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & CucumberUdaya Kiran
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platformnirajrules
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725miguel dominguez
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725MortazaJohari
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
End-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemEnd-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemAlex Mikitenko
 

Ähnlich wie Distribute Rails Apps as Standalone Executables (20)

Rails
RailsRails
Rails
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
 
Building Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkBuilding Application with Ruby On Rails Framework
Building Application with Ruby On Rails Framework
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Building Application With Ruby On Rails Framework
Building Application With Ruby On Rails FrameworkBuilding Application With Ruby On Rails Framework
Building Application With Ruby On Rails Framework
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
All girlhacknight intro to rails
All girlhacknight intro to railsAll girlhacknight intro to rails
All girlhacknight intro to rails
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platform
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
End-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemEnd-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystem
 
Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Rspec
RspecRspec
Rspec
 

Mehr von tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

Mehr von tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Kürzlich hochgeladen

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

Distribute Rails Apps as Standalone Executables

  • 2. Table of Contents Distributing Rails Applications............................................................................................................1 A Tutorial ...................................................................................................................................1 . 1. Introduction........................................................................................................................................2 2. Ingredients..........................................................................................................................................3 2.1. Ruby.....................................................................................................................................3 2.2. Rails.....................................................................................................................................3 2.3. SQLite..................................................................................................................................3 2.4. Ruby-SQLite Bindings........................................................................................................3 2.5. Tar2RubyScript ...................................................................................................................3 . 2.6. RubyScript2Exe...................................................................................................................3 3. The Steps.............................................................................................................................................5 3.1. Setup the Environment........................................................................................................5 . 3.2. Create the SQLite Database.................................................................................................5 3.3. Develop the Rails Application.............................................................................................5 3.4. Create the RBA from the Application with Tar2RubyScript..............................................6 3.5. Create the standalone Executable with RubyScript2Exe .....................................................8 4. Conclusion..........................................................................................................................................9 Distributing Rails Applications - A Tutorial i
  • 3. Distributing Rails Applications A Tutorial Sun Dec 24 19:01:32 UTC 2006 Erik Veenstra <erikveen@dds.nl> Distributing Rails Applications - A Tutorial 1
  • 4. 1. Introduction (Before we start: On real production servers, don't "deploy" a Rails application like this. That's not a good idea. But if you only want to ship your demo, well, read on...) I get a lot of emails about packing and distributing Rails applications with Tar2RubyScript and RubyScript2Exe. It obviously wasn't easy to come up with the steps that have to be taken to transform a Rails application into a standalone application. Since I never built a Rails application myself, I wasn't even sure if it was possible at all. That's why I decided to write this tutorial. In this tutorial, we'll go through the following steps: 1. Setup the environment 2. Create the SQLite database 3. Develop the Rails application 4. Create the RBA (= Ruby archive) from the application with Tar2RubyScript 5. Create the standalone executable with RubyScript2Exe Before we begin, I assume that you've installed the following components (The version numbers are the versions I've installed myself.): • Ruby (1.8.2) • Rails (0.14.3) • SQLite (2.8.15) • Ruby-SQLite bindings (2.2.3) Since a lot of information about the installation of each individual component can be found on the 'Net, I skip the do-this-to-install-that part. Well, we have to start somewhere... For this tutorial, I used the RubyInstaller version of Ruby on Windows 2000 and installed both Rails and SQLite-Ruby with RubyGems. But you could use Linux as well. Every single step is the same on both platforms. The differences are just textual: back slashes instead of forward slashes, c:> instead of # and copy instead of cp. That's it. More general information about distributing Ruby applications (especially Tar2RubyScript, RubyScript and how they work together) can be found here. Distributing Rails Applications - A Tutorial 2
  • 5. 2. Ingredients 2.1. Ruby Ruby is "the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable". See the Ruby site for more information about Ruby. 2.2. Rails Rails is "a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less code than most frameworks spend doing XML sit-ups". See the Rails site for more information about Rails. 2.3. SQLite SQLite is "a self-contained, embeddable, zero-configuration SQL database engine". See the SQLite site for more information about SQLite. 2.4. Ruby-SQLite Bindings Ruby-SQLite "allows Ruby programs to interface with the SQLite database engine". See the SQLite-Ruby site for more information about SQLite-Ruby. 2.5. Tar2RubyScript Tar2RubyScript "transforms a directory tree, containing your application, into one single Ruby script, along with some code to handle this archive. This script can be distributed to our friends. When they've installed Ruby, they just have to double click on it and your application is up and running!" See the Tar2RubyScript site for more information about Tar2RubyScript. This is all you need: tar2rubyscript.rb. A "gem install tar2rubyscript" will do, too. 2.6. RubyScript2Exe RubyScript2Exe "transforms your Ruby script into a standalone, compressed Windows, Linux or Mac OS X (Darwin) executable. You can look at it as a "compiler". Not in the sense of a Distributing Rails Applications - A Tutorial 3
  • 6. 2. Ingredients source-code-to-byte-code compiler, but as a "collector", for it collects all necessary files to run your script on an other machine: the Ruby script, the Ruby interpreter and the Ruby runtime library (stripped down for this script). Anyway, the result is the same: a standalone executable (application.exe). And that's what we want!" See the RubyScript2Exe site for more information about RubyScript2Exe. This is all you need: rubyscript2exe.rb. A "gem install rubyscript2exe" will do, too. Distributing Rails Applications - A Tutorial 4
  • 7. 3. The Steps 3.1. Setup the Environment First of all, create a simple Rails application and test it: C:rails> rails demo C:rails> cd demo C:railsdemo> ruby scriptserver Point your browser to http://localhost:3000/. 3.2. Create the SQLite Database Now let's create a test database: With Ruby: C:railsdemo> ruby require "rubygems" require_gem "sqlite-ruby" SQLite::Database.new("demo_dev.db").execute( "create table books (id integer primary key, title varchar(255), author varchar(255));") ^D # That's ctrl-D... Or with SQLite: C:railsdemo> sqlite demo_dev.db SQLite version 2.8.15 Enter ".help" for instructions sqlite> create table books ...> (id integer primary key, ...> title varchar(255), ...> author varchar(255) ...> ); sqlite> .quit And copy this empty database to a test database and a production database, for later usage: C:railsdemo> copy demo_dev.db demo_tst.db C:railsdemo> copy demo_dev.db demo_prd.db 3.3. Develop the Rails Application Configure the application to use SQLite: C:railsdemo> notepad configdatabase.yml Replace the contents of this file with something like this: Distributing Rails Applications - A Tutorial 5
  • 8. 3. The Steps development: adapter: sqlite database: demo_dev.db test: adapter: sqlite database: demo_tst.db production: adapter: sqlite database: demo_prd.db Create the model and the controller: C:railsdemo> ruby scriptgenerate model Book C:railsdemo> ruby scriptgenerate controller Book C:railsdemo> notepad appcontrollersbook_controller.rb Edit this file, so it looks like this: class BookController < ApplicationController scaffold :book end Test it: C:railsdemo> ruby scriptserver Point your browser to http://localhost:3000/book/list and add some new books. 3.4. Create the RBA from the Application with Tar2RubyScript 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:railsdemo> notepad configenvironment.rb Add this at the top of the file: module Rails class Configuration def database_configuration conf = YAML::load(ERB.new(IO.read(database_configuration_file)).result) Distributing Rails Applications - A Tutorial 6
  • 9. 3. The Steps 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") end end end conf end end end This overwrites Rails::Configuration#database_configuration, which was originally defined as: module Rails class Configuration def database_configuration YAML::load(ERB.new(IO.read(database_configuration_file)).result) end end end 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"}} Tar2RubyScript also needs init.rb, which is the entry point. So we create it: C:railsdemo> notepad init.rb It looks like this: at_exit do require "irb" require "drb/acl" require "sqlite" end load "script/server" Distributing Rails Applications - A Tutorial 7
  • 10. 3. The Steps The require's are a little trick. If you start and stop a Rails application, without any interaction with a browser, not all require's of the program are encountered, so RubyScript2Exe might miss some libraries. Requiring them at the end avoids this problem. It's just bad behavior (in casu of Rails...) to require some libraries halfway a program... Now it's time to pack the application into an RBA: C:railsdemo> cd .. C:rails> ruby tar2rubyscript.rb demo Tar2RubyScript creates demo.rb, which is the RBA. This RBA contains both the application and the databases. But we're not going to use this embedded user data (do you remember oldlocation?), so we copy the DB's to the current directory: C:rails> copy demo*.db Now we can test our RBA: C:rails> ruby demo.rb [-e environment] Once again: the DB's we use when running as RBA are not the same as the DB's we use when running the application the old way! The sets are simply in another directory. 3.5. Create the standalone Executable with RubyScript2Exe Creating a standalone executable is as simple as this: C:rails> ruby rubyscript2exe.rb demo.rb ^C (When Rails is started...) # That's ctrl-C... RubyScript2Exe creates demo.exe (or demo_linux or demo_darwin, depending on your platform). Now we copy demo.exe and demo_*.db to our USB memory stick, drive to our customer (he hasn't Ruby...) and simply start the application: C:rails> demo.exe [-e environment] Distributing Rails Applications - A Tutorial 8
  • 11. 4. Conclusion No installation of Ruby, no installation of RubyGems, no installation of the various gems, no installation of SQLite; There's only one executable! Another conclusion concerns Rails. Rails has two architectural shortcomings (related to distributing the application): • The user data isn't separated from the application itself. • require is used halfway the program. This is not RubyScript2Exe-friendly. As we've seen, both shortcomings can be worked around. aior all allinone allinoneruby applications archive bin browser code codesnippet codesnippets compile compiler computer computerlanguage dialog dialogs distribute distributing distributingrubyapplications distribution eee eee-file eeefile erik erikveen erikveenstra exe executable exerb file graphical graphicaluserinterface gui gz html http httpserver iloveruby interface jar jit just justintime lang language one pack package packaging packing packingrubyapplications programming programminglanguage rar rb rb2bin rb2exe rba rbarchive rbtobin rbtoexe rbw ruby ruby2bin ruby2exe rubyapplications rubyarchive rubycompiler rubyscript rubyscript2 rubyscript2exe rubyscripts rubyscripttoexe rubytobin rubytoexe rubyweb rubywebdialog rubywebdialogs script scripts server snippet snippets t2rb t2rs tar tar2rb tar2rbscript tar2rs tar2rscript time ui user userinterface veenstra web webbrowser webdialog webdialogs window windowinbrowser windows wrap wrapper wxruby zip Distributing Rails Applications - A Tutorial 9