Depot Sample in Rails 2.0, Step 1

Depot for MySQL5.0, Rails2.0 in WindowXP,
# means comments, Hope you can enjoy it.

Objective: To build the basic skeleton of depot


1. create depot rails project
rails depot

2. edit config/database.yml
development:
  adapter: mysql
  database: depot_development
  username: root
  password: admin
  host: 127.0.0.1

test:
  adapter: mysql
  database: depot_test
  username: root
  password: admin
  host: 127.0.0.1

production:
  adapter: mysql
  database: depot_production
  username: root
  password: admin
  host: 127.0.0.1


3. create database defined in database.yml
rake db:drop:all #drop database defined in database.yml
rake db:create:all #create database defined in database.yml
rake db:version #print database version

#rake db:rollback #rollback database to last version, do not need to type this in this sample

4. create product RESTful
ruby script/generate scaffold product title:string description:text image_url:string
#Remember now that Rails 2.0 is RESTful by default. The only difference here is that the ‘scaffold’ behaves like the ‘scaffold_resource’ we had before, and the old non-RESTful scaffold is gone. You also don’t have the ActionController class method ‘scaffold’ that dynamically populated your empty controller with default actions. So, everything scaffold we do is RESTful now. It will create the usual suspects: Controller, Helper, Model, Migration, Unit Test, Functional Test.
#Please check app/controllers/products_controller.rb for confirm

5. Migrate product into database.
rake db:migrate
#Please check the coressponding database with the table named "products" for confirm

6. start Webrick server.
ruby script/server

7. test depot in web browser.
http://localhost:3000/products

你可能感兴趣的:(Web,mysql,Ruby,Rails)