Getting Started with Rails 2.0 Scaffold
- Download & Install 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
command:
sudo /usr/local/mysql/bin/mysqld_safe --console - Creat the database using the following command:
cd books
jruby -S rake db:create
This creates the database defined by RAILS_ENV (Development is default). Here are some other new database-related commands:
db:create:allCreate all the databases (_Development, _Test, _Production) db:dropDrops your database db:resetDrop and Re-create your database, including migrations - Generate a scaffold using the following command:
jruby script/generate scaffold book title:string author:string isbn:string description:text
The output of the command looks like:exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/books
exists app/views/layouts/
exists test/functional/
exists test/unit/
create app/views/books/index.html.erb
create app/views/books/show.html.erb
create app/views/books/new.html.erb
create app/views/books/edit.html.erb
create app/views/layouts/books.html.erb
create public/stylesheets/scaffold.css
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/book.rb
create test/unit/book_test.rb
create test/fixtures/books.yml
create db/migrate
create db/migrate/001_create_books.rb
create app/controllers/books_controller.rb
create test/functional/books_controller_test.rb
create app/helpers/books_helper.rb
route map.resources :books
There is no need to create the model explicitly as was the case in previous version of Rails. This creates the "db/migrate/001_create_books.rb" migration which looks likeclass CreateBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.string :title
t.string :author
t.string :isbn
t.text :description
t.timestamps
end
end
def self.down
drop_table :books
end
end - Create the database tables using the following command:
jruby -S rake db:migrate - Deploy the application on WEBrick using the following
command:
jruby script/server
The application is now available at "http://localhost:3000/books" and looks like:

- Click on "New book" to see a page as shown below (with
values entered):

Click on Create button. After 2 entries have been entered, it looks like as shown below:

You can also deploy this application easily on GlassFish v3 gem. Just follow the instructions here and enjoy!
I'll post a follow up blog where this is much more simplifed using NetBeans 6.1 builds where JRuby 1.1 and Rails 2.0.2 are already integrated.
(1 vote)
- Login or register to post comments
- 3024 reads
- Flag as offensive
- Email this Story
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)






