Posted by arungupta
on February 20, 2008 at 12:09 AM PST
2.0 changes the way
works. This blog walks you through the steps to create a simple CRUD
application using Scaffold in Rails 2.0.
- Download & Install
href="http://dist.codehaus.org/jruby/">JRuby 1.1 RC2.
- Install Rails using the following command:
jruby -S gem install rails
- Create a new Rails app using the following command:
cd samples; mkdir rails; cd rails
jruby -S rails books -d mysql
- Start MySQL server in a different shell using the following
sudo /usr/local/mysql/bin/mysqld_safe --console
- Creat the database using the following command:
jruby -S rake db:create
This creates the database defined by RAILS_ENV (Development is
default). Here are some other new database-related commands:
border="0" cellpadding="2" cellspacing="2">
|Create all the databases (_Development, _Test,
|Drops your database
|Drop and Re-create your database, including
- Generate a scaffold using the following command:
jruby script/generate scaffold book title:string author:string
The output of the command looks like:
There is no need to create the model explicitly as was the case in
previous version of Rails. This creates the "
migration which looks like:
class CreateBooks < ActiveRecord::Migration
create_table :books do |t|
- Create the database tables using the following command:
jruby -S rake db:migrate
- Deploy the application on WEBrick using the following
The application is now available at "
and looks like:
alt="Rails2 CRUD Blank Page" title="Rails2 CRUD Blank Page"
- Click on "New book" to see a page as shown below (with
alt="Rails2 CRUD New Entry" title="Rails2 CRUD New Entry"
Click on Create button. After 2 entries
have been entered, it looks like as shown below:
alt="Rails 2 CRUD Multiple Entries"
title="Rails 2 CRUD Multiple Entries"
That's it, you've created a simple Rails 2.0 CRUD application.
You can also deploy this application easily on
v3 gem. Just follow the instructions
I'll post a follow up blog where this is much more simplifed using
6.1 builds where JRuby 1.1 and Rails 2.0.2 are already