2008年3月23日 星期日

build a basic web site with ruby on rails2

1. use rail to create default directories and files
rails -d mysql bookStore
-d mysql: use mysql as database

2. Tell rail information about database
configure config/database.yml

3. create the database
rake db:create:all

4.create the model for user account
script/generate model Account
app/models/account.rb is created
db/migrate/001_create_accounts.rb is created

app/models/account.rb
class Account < ActiveRecord::Base

end

db/migrate/001_create_accounts.rb
class CreateAccounts < ActiveRecord::Migration
def self.up
create_table :accounts do |t|
t.string :name
t.string :password
t.string :email
t.timestamps
end
end

def self.down
drop_table :accounts
end
end

5. do migration(create the table in the database)
rake db:migrate

沒有留言: