Wednesday February 20, 2008
TOTD #28: Getting Started with Rails 2.0 Scaffold
Rails
2.0 changes the way Scaffold
works. This blog walks you through the steps to create a simple CRUD
application using Scaffold in Rails 2.0.
jruby -S gem install railscd samples; mkdir rails; cd rails
jruby -S rails books -d mysqlsudo /usr/local/mysql/bin/mysqld_safe --consolecd books
jruby -S rake db:create
db:create:all |
Create all the databases (_Development, _Test, _Production) |
db:drop |
Drops your database |
db:reset |
Drop and Re-create your database, including migrations |
jruby script/generate scaffold book title:string author:string
isbn:string description:text
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 :booksdb/migrate/001_create_books.rb"
migration which looks like:class 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
endjruby -S rake db:migrate
jruby script/serverhttp://localhost:3000/books"
and looks like:


Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
Posted by Arun Gupta's Blog on March 13, 2008 at 08:23 PM PDT #
Posted by Arun Gupta's Blog on April 09, 2008 at 09:02 AM PDT #
Posted by Arun Gupta's Blog on June 19, 2008 at 06:46 AM PDT #
Posted by Arun Gupta's Blog on July 02, 2008 at 06:24 AM PDT #