==============================================================
1、如果已经安装了sqlite3的话可以跳到第3步,否则下载sqlite3.exe和sqlite3.dll(已上传这两个文件,在页面最下面有下载)两个文件放入ruby的安装目录下的bin目录,比如我的是D:\ruby\bin\
2、执行以下命令
gem install sqlite3-ruby安装sqlite3的ruby驱动。
3、现在就可以进行ROR开发了。比如我这里要实现mybook,首先执行
rails mybook -d mysql之所以加上"-d mysql"是将数据库改为mysql(默认为sqlite3),然后要修改/mybook/config/下面的database.yml,比如我的修改如下:
development: adapter: mysql encoding: utf8 database: mybook_development username: root password: root host: localhost test: adapter: mysql encoding: utf8 database: mybook_test username: root password: root host: localhost production: adapter: mysql encoding: utf8 database: mybook_production username: root password: root host: localhost
4、建立数据库,执行
cd mybook rake db:create:all,成功的话cmd会显示:
D:\rubyapps\mybook>rake db:create:all (in D:/rubyapps/mybook)
此时查看MySQL可以看到多出来三个表,如下图所示:
5、建立model
D:\rubyapps\mybook>ruby script/generate scaffold Mybook title:string description:text buydate:datetime
最后
rake db:migrate,成功的话会有:
(in D:/rubyapps/mybook) == 1 CreateMybooks: migrating ================================================= -- create_table(:mybooks) -> 0.0780s == 1 CreateMybooks: migrated (0.0780s) ========================================
此时查看MySQL,可以看到数据库结构如下:
表的结构如下:
6、运行一下看看吧:)
ruby script/server然后在浏览器里面输入http://localhost:3000/mybooks,我这里的效果如下: