Installing Ruby on Rail in Puppy

March 17, 2007 at 3:49 pm 8 comments

Ruby on Rails is an open source web framework for developing web based, database driven application based on the Model-View-Controller model. At the minimum, the installation will consists of the following:

  • Ruby Programming Language
  • Ruby GEM library
  • Ruby on Rail framework
  • Ruby Database Driver
  • Database

The most common database is MySQL. However, compiling MySQL is tricky and the database has a rather large footprint to fit on an USB flash drive. Fortunately, Puppy comes with a Sqlite3, which we can use as the database.

Ruby on Rail has a built-in webserver call WeBrick. Optionally, we can install a standalone web server like Apache or Lighttpd.

The following are instruction for installing Ruby on Rails on Puppy Linux 2.14 with the minimal component needed to play around with Ruby on Rail.

  1. Before you start, make sure that you have the developer sfs installed. The Puppy developer SFS usually exists as a devx_xxx.sfs file where xxx is the version number of Puppy. You will need the developer SFS when you run gem.
  2. Install Ruby on Rails. I have create a dotpet to facilitate the install. All you need to do is download the Ruby DotPet file and open it from Puppy’s filemanager Rox. It will prompt you to install the package. Press Install.
  3. If you wish to install the interactive documentation, download the Ruby Doc file and open it from Rox. It will prompt you to install. Press Install.
  4. Download the Ruby GEM library. Download the latest tgz file into my-document. Untar the file by running the following command. I debated creating a DotPet for this but the tools weren’t able to record gem scripts, so we will download and run GEM:
    tar -xvf rubygems-0.9.2.tgz
  5. Once the file is extracted, we can run the setup file to install Ruby Gem.
    cd rubygems-0.9.2
    ruby setup.rb
  6. Use Ruby GEM to install Ruby on Rails. Note that you must have an internet connection open because Ruby GEM will connect to a server and download the software. If install fails, try again (I had to try twice).
    gem install rails --include-dependencies
  7. Use Ruby GEM to install the Sqlite3 driver sqlite3-ruby. Previous version of the driver required the SWIG package, but sqlite3-ruby 1.2.0 removed that dependency.
    gem install sqlite3-ruby
  8. You are prompt to select which gem to install. Select the latest GEM for your OS (in this case, it’s sqlite3-ruby 1.2.1).

Testing the Installation

To test if the framework is install properly, we need to create a simple program that exercise the entire framework.

  1. Open a terminal window and go to a directory. Enter the following command to create a Ruby project:
    rails smoketest
    This will create a directory call smoketest and a group of subdirectories.
  2. Next, we need to create a sqlite3 database and create a simple table in it.
    cd smoketest
    sqlite3 smoketest_development "create table books (isbn integer primary key not null, title varchar(25) not null);"
    This will create a database call smoketest_development and populated with a empty table books. Normally, we would have a development, test, and production database, but this is only a test so we will just create one.
  3. edit config/database.yml file. Change the adapter from “mysql” to “sqlite3”. This file specifies the development test and production database and the user account to connect.
  4. We’ll use Ruby to generate a scaffold. The scaffold generator creates a model “book” and map it directly to the database table “books”, it also generates a controller to manipulate the table, and a view to display the content of the table in a webpage.
    ruby script/generate scaffold Book RubyTest
  5. Start the Ruby Web Server by running the following command in a terminal.
    ruby script/server
    You should get a prompt that WEBrick is booting.
  6. The web server defaults to port 3000. We can connect to the server by hitting the following url:
    http://localhost:3000

    You should get the standard Ruby “Welcome aboard” page.
  7. If you can get to the Ruby server’s welcome aboard page, try hitting the test page:

    http://localhost:3000/ruby_test
  8. The screen should display the page for the table books. You can try to add a new book but clicking on the new book link.
Advertisements

Entry filed under: linux, Puppy Linux.

Creating a Ruby DotPet in Puppy 2.14+ Creating a XML Document from scratch without using a file in C#

8 Comments Add your own

  • 1. Tone  |  October 14, 2008 at 5:13 pm

    I am using puppy 4 and having a problem with installing sqlite3-ruby. When I ruin the command gem install sqlite3-ruby I get the following error.

    ERROR: Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension.

    /usr/local/bin/ruby extconf.rb install sqlite3-ruby
    checking for fdatasync() in -lrt… no
    checking for sqlite3.h… no

    make
    sh: make: command not found

    Can you advise? I’d be very grateful.

    Thanks for the tutorial 🙂

    Reply
  • 2. paulsiu  |  October 21, 2008 at 6:36 am

    I reinstall Puppy on my virtual machine. I notice that one problem is that you need to have a working internet connection to install the gems.

    I installed Puppy 4.1 with Ruby 1.8.7 and Gem 1.3.0. Are you using anything different.

    Reply
  • 3. paulsiu  |  October 23, 2008 at 8:40 am

    Never mind, I figured it out, you need to have the development library installed. So make sure your puppy has the devx_xxx.sfs installed on boot up. When you do a gem install sqlite3-ruby, it’s actually trying to reed the sqlite3.h header file, which is in devx sfs.

    Reply
  • 4. Tone  |  October 23, 2008 at 4:12 pm

    Installed devx and the system is working I think – but I do have another problem…
    all goes well until I script/generate scaffold, when I get this error

    # ruby script/generate scaffold Book RubyTest
    Gem::SourceIndex#search support for Regexp patterns is deprecated
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/rails_generator/lookup.rb:211:in `each’ is outdated
    exists app/models/
    exists app/controllers/
    exists app/helpers/
    create app/views/books
    exists app/views/layouts/
    exists test/functional/
    exists test/unit/
    exists public/stylesheets/
    create app/views/books/index.html.erb
    wrong number of arguments (1 for 2)

    when I point my browser to the new page, I get a 505 Internal Server Error (the Welcome Aboard page is fine localhost:3000)

    Any further help would be gratefully received.

    Reply
  • 5. paulsiu  |  October 24, 2008 at 7:29 am

    They changed the syntax in the Rails 2.0 for the scaffolding (I notice that you are using Rails 2.1.1).

    See: http://fairleads.blogspot.com/2007/12/rails-20-and-scaffolding-step-by-step.html

    I am going to have to write a new tutorial 🙂

    On another note, if you are using Ruby 1.9.0, you may get another error and would require a patch. What version of Ruby are you using?

    Reply
  • 6. Tone  |  October 24, 2008 at 11:01 am

    I am using:
    ruby 1.8.6 (2007-03-13 patchlevel 0) [i486-linux]

    Thanks again for your help 🙂

    Reply
  • 7. Link by umeee  |  February 5, 2010 at 9:06 am

    ERROR: Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension

    Reply
  • 8. Ruby Programmer  |  February 22, 2014 at 7:36 am

    Thanks Bro it worked!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

March 2007
M T W T F S S
« Feb   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

Most Recent Posts


%d bloggers like this: