Depot Sample in Rails 2.0, Step 1

本文介绍如何使用Rails2.0在Windows XP环境下搭建名为Depot的应用程序。主要步骤包括创建Rails项目、配置数据库连接、生成产品资源、迁移数据库、启动服务器及进行网页测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Depot for MySQL5.0, Rails2.0 in WindowXP,
# means comments, Hope you can enjoy it.
[b][color=red]
Objective: To build the basic skeleton of depot[/color][/b]

1. create depot rails project
[b][color=blue]rails depot[/color][/b]

2. edit config/database.yml
[b][color=blue]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[/color][/b]

3. create database defined in database.yml
[b][color=blue]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[/color][/b]
#rake db:rollback #rollback database to last version, do not need to type this in this sample

4. create product RESTful
[b][color=blue]ruby script/generate scaffold product title:string description:text image_url:string[/color][/b]
#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.
[b][color=blue]rake db:migrate[/color][/b]
#Please check the coressponding database with the table named "products" for confirm

6. start Webrick server.
[b][color=blue]ruby script/server[/color][/b]

7. test depot in web browser.
[b][color=blue]http://localhost:3000/products[/color][/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值