Agile Web Development with Rails depot例程 数据库配置
Posted on 2008-10-29 13:38 noAh.... 阅读(476) 评论(0) 收藏 举报若是点击刚刚的静态页面中的About your application’s environment,我们会看到Rails已经对我们当前的配置进行了检测。很可惜,会出现一个很严重的错误,到现在我们只是在建立depot的时候申明了我们将使用mysql,剩下就没有对数据库进行过任何操作。
我们暂时关闭server服务器(在命令窗口按ctrl+c),输入>rake db:create,便会创建一个于depot相关的数据库。在这个例程中所有需要保存的数据库信息,都会放在这个数据库内。
打开server服务器(>ruby script/server),进入http://localhost:3000,点击About your application’s environment便能看到我们当前的配置环境。
打开mysql的命令控制台,我们能找到与depot相关的数据库,名为depot_development。
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| depot_development |
| mysql |
| test |
+--------------------+
4 rows in set (0.03 sec)
mysql>
在/depot/config中的database.yml文件中,保存了相关的数据库信息。
development:
adapter: mysql
encoding: utf8
database: depot_development
username: root
password:
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql
encoding: utf8
database: depot_test
username: root
password:
host: localhost
production:
adapter: mysql
encoding: utf8
database: depot_production
username: root
password:
host: localhost
数据移植。rake db:migrate
上面这个命令要在例程中用到多次,功能是将rails应用中间的有关的数据类型的更改迁移映射到数据库中间去。比如创建了一个scaffold(后面我们会用到),我们需要用rake db:migrate将其迁移到数据库。