SlideShare a Scribd company logo
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

More Related Content

What's hot

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.uk
Graham Tackley
 
Play framework
Play frameworkPlay framework
Play framework
Andrew Skiba
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Servlets
ServletsServlets
Servlets
ramesh kumar
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
Kevin Webber
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
Gary Yeh
 
Docker toolbox
Docker toolboxDocker toolbox
Docker toolbox
Yonghwee Kim
 
Installaling Puppet Master and Agent
Installaling Puppet Master and AgentInstallaling Puppet Master and Agent
Installaling Puppet Master and Agent
Ranjit 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 awesomeness
Ramit 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
 
Rails Security
Rails SecurityRails Security
Rails Security
Wen-Tien Chang
 
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
Lukasz Lysik
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
nartamonov
 
Servlet 01
Servlet 01Servlet 01
Servlet 01
Bharat777
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
Mazenetsolution
 
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 Framework
Warren 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
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
CodeOps Technologies LLP
 

What's hot (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
 

Viewers also liked

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
drsolapurkar
 
p10
p10p10
Informing Faculty Case Template
Informing Faculty Case TemplateInforming Faculty Case Template
Informing Faculty Case Template
tutorialsruby
 
FreshAir2008
FreshAir2008FreshAir2008
FreshAir2008
tutorialsruby
 
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
tutorialsruby
 
M.S.Transcript
M.S.TranscriptM.S.Transcript
M.S.Transcript
Kanutsanun Bouking
 

Viewers also liked (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
 

Similar to rails.html

Rails
RailsRails
Rails
SHC
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
Jean-Baptiste Feldis
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
Viridians
 
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
Edureka!
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
anides
 
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
Vineet Chaturvedi
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
David Mc Donagh
 
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 rails
Nola Stowe
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
akankshita satapathy
 
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
Udaya Kiran
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
Rubyc Slides
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platform
nirajrules
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
miguel dominguez
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
MortazaJohari
 
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
arman 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 ecosystem
Alex Mikitenko
 
Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
Jim Jones
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
Momentum Design Lab
 
Rspec
RspecRspec

Similar to rails.html (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
 

More from 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 – INS0
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
CSS
CSSCSS
CSS
CSSCSS
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

More from 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
 

Recently uploaded

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 

rails.html

  • 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