rails2.02快速体验 - rails - Ruby - JavaEye论坛
来源:百度文库 编辑:神马文学网 时间:2024/04/29 21:12:40
如果是windows下的用户,而又不是使用instant Rail,那么需要进行以下步骤。
1、下载sqlite的exe和dll文件,然后将其放入系统path。(有些linux发行版本默认安装了sqlite,无需再次安装)
2、确定你下载的sqlite版本,如果是sqlite3(注意放入path目录的文件应该保持的sqlite3.exe和sqlite3.dll,不要改名为sqlite.exe和sqlite.dll),在命令行运行
Ruby代码
gem install sqlite3-ruby
gem install sqlite3-ruby
安装sqlite3的ruby驱动。
3、新建一个Rails程序
本想自己写点代码,可是网上有个5行的todo,我就懒了。
Ruby代码
rails todo
rails todo
这时使用的是默认的sqlite3做数据库。如果你希望使用mysql,则输入
Ruby代码
rails todo -d mysql
rails todo -d mysql
有点rails经验的人会发现这个“-d”的新东西。如果你是在mysql下,往往需要修改config目录下的database.yml文件。
Ruby代码
development:
adapter: mysql
encoding: utf8
database: blog_development
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
test:
adapter: mysql
encoding: utf8
database: blog_test
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
production:
adapter: mysql
encoding: utf8
database: blog_production
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
development:adapter: mysqlencoding: utf8database: blog_developmentusername: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.socktest:adapter: mysqlencoding: utf8database: blog_testusername: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.sockproduction:adapter: mysqlencoding: utf8database: blog_productionusername: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.sock 不过有些人觉得这样很不爽,于是有了这样的Ruby代码
defaults: &defaults
adapter: mysql
encoding: utf8
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
development:
database: blog_development
<<: *defaults
test:
database: blog_test
<<: *defaults
production:
database: blog_production
<<: *defaults
defaults: &defaultsadapter: mysqlencoding: utf8username: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.sockdevelopment:database: blog_development<<: *defaultstest:database: blog_test<<: *defaultsproduction:database: blog_production<<: *defaults
当然出于安全考虑,谁也不会用这样的配置去搞到生产环境下。不过这样看着确实爽多了。
2、新建数据库
既然上面配置好了,那么下面就该实际的联起来用了。
Ruby代码
cd todo
rake db:create:all
cd todorake db:create:all
这里又一个新东西“rake db:create:all”,它将给你建立起各个数据库,现在不需要你自己去手工搞了。是不是比以前爽了。
Ruby代码
D:\work\todo>rake db:create:all
(in D:/work/todo)
"db/development.sqlite3 already exists"
"db/production.sqlite3 already exists"
"db/test.sqlite3 already exists"
D:\work\todo>rake db:create:all(in D:/work/todo)"db/development.sqlite3 already exists""db/production.sqlite3 already exists""db/test.sqlite3 already exists" 上面是我这里运行成功的提示。
下面是个说明
Ruby代码
db:charset Retrieves the charset for the current environment’s database
db:collation Retrieves the collation for the current environment’s database
db:create Create the database defined in config/database.yml for the current RAILS_ENV
db:create:all Create all the local databases defined in config/database.yml
db:drop Drops the database for the current RAILS_ENV
db:drop:all Drops all the local databases defined in config/database.yml
db:reset Drops and recreates the database from db/schema.rb for the current environment.
db:rollback Rolls the schema back to the previous version. Specify the number of steps with STEP=n
db:version Retrieves the current schema version number
db:charset Retrieves the charset for the current environment’s databasedb:collation Retrieves the collation for the current environment’s databasedb:create Create the database defined in config/database.yml for the current RAILS_ENVdb:create:all Create all the local databases defined in config/database.ymldb:drop Drops the database for the current RAILS_ENVdb:drop:all Drops all the local databases defined in config/database.ymldb:reset Drops and recreates the database from db/schema.rb for the current environment.db:rollback Rolls the schema back to the previous version. Specify the number of steps with STEP=ndb:version Retrieves the current schema version number
这里注意有了个新的“db:rollback”命令,比以前用爽多了。
Ruby代码
rake db:migrate VERSION=xxx
rake db:migrate VERSION=xxx 可以说byebye了。
3、真正的算代码的东西就一行
Ruby代码
ruby script/generate scaffold Todo title:string body:text done:boolean due:datetime
ruby script/generate scaffold Todo title:string body:text done:boolean due:datetime
前几个月大家还在感叹model里面竟然可以那样sexyness,现在看看这个直接在命令行搞定,现在该用啥词形容好呢。
最后别忘记
Ruby代码
rake db:migrate
rake db:migrate
4、运行起来看看。
Ruby代码
ruby script/server
ruby script/server
然后用浏览器访问下面的链接127.0.0.1:3000/todos
搞定了一个todolist。
1、下载sqlite的exe和dll文件,然后将其放入系统path。(有些linux发行版本默认安装了sqlite,无需再次安装)
2、确定你下载的sqlite版本,如果是sqlite3(注意放入path目录的文件应该保持的sqlite3.exe和sqlite3.dll,不要改名为sqlite.exe和sqlite.dll),在命令行运行
Ruby代码
gem install sqlite3-ruby
gem install sqlite3-ruby
安装sqlite3的ruby驱动。
3、新建一个Rails程序
本想自己写点代码,可是网上有个5行的todo,我就懒了。
Ruby代码
rails todo
rails todo
这时使用的是默认的sqlite3做数据库。如果你希望使用mysql,则输入
Ruby代码
rails todo -d mysql
rails todo -d mysql
有点rails经验的人会发现这个“-d”的新东西。如果你是在mysql下,往往需要修改config目录下的database.yml文件。
Ruby代码
development:
adapter: mysql
encoding: utf8
database: blog_development
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
test:
adapter: mysql
encoding: utf8
database: blog_test
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
production:
adapter: mysql
encoding: utf8
database: blog_production
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
development:adapter: mysqlencoding: utf8database: blog_developmentusername: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.socktest:adapter: mysqlencoding: utf8database: blog_testusername: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.sockproduction:adapter: mysqlencoding: utf8database: blog_productionusername: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.sock 不过有些人觉得这样很不爽,于是有了这样的Ruby代码
defaults: &defaults
adapter: mysql
encoding: utf8
username: root
password: root
socket: /opt/local/var/run/mysql5/mysqld.sock
development:
database: blog_development
<<: *defaults
test:
database: blog_test
<<: *defaults
production:
database: blog_production
<<: *defaults
defaults: &defaultsadapter: mysqlencoding: utf8username: rootpassword: rootsocket: /opt/local/var/run/mysql5/mysqld.sockdevelopment:database: blog_development<<: *defaultstest:database: blog_test<<: *defaultsproduction:database: blog_production<<: *defaults
当然出于安全考虑,谁也不会用这样的配置去搞到生产环境下。不过这样看着确实爽多了。
2、新建数据库
既然上面配置好了,那么下面就该实际的联起来用了。
Ruby代码
cd todo
rake db:create:all
cd todorake db:create:all
这里又一个新东西“rake db:create:all”,它将给你建立起各个数据库,现在不需要你自己去手工搞了。是不是比以前爽了。
Ruby代码
D:\work\todo>rake db:create:all
(in D:/work/todo)
"db/development.sqlite3 already exists"
"db/production.sqlite3 already exists"
"db/test.sqlite3 already exists"
D:\work\todo>rake db:create:all(in D:/work/todo)"db/development.sqlite3 already exists""db/production.sqlite3 already exists""db/test.sqlite3 already exists" 上面是我这里运行成功的提示。
下面是个说明
Ruby代码
db:charset Retrieves the charset for the current environment’s database
db:collation Retrieves the collation for the current environment’s database
db:create Create the database defined in config/database.yml for the current RAILS_ENV
db:create:all Create all the local databases defined in config/database.yml
db:drop Drops the database for the current RAILS_ENV
db:drop:all Drops all the local databases defined in config/database.yml
db:reset Drops and recreates the database from db/schema.rb for the current environment.
db:rollback Rolls the schema back to the previous version. Specify the number of steps with STEP=n
db:version Retrieves the current schema version number
db:charset Retrieves the charset for the current environment’s databasedb:collation Retrieves the collation for the current environment’s databasedb:create Create the database defined in config/database.yml for the current RAILS_ENVdb:create:all Create all the local databases defined in config/database.ymldb:drop Drops the database for the current RAILS_ENVdb:drop:all Drops all the local databases defined in config/database.ymldb:reset Drops and recreates the database from db/schema.rb for the current environment.db:rollback Rolls the schema back to the previous version. Specify the number of steps with STEP=ndb:version Retrieves the current schema version number
这里注意有了个新的“db:rollback”命令,比以前用爽多了。
Ruby代码
rake db:migrate VERSION=xxx
rake db:migrate VERSION=xxx 可以说byebye了。
3、真正的算代码的东西就一行
Ruby代码
ruby script/generate scaffold Todo title:string body:text done:boolean due:datetime
ruby script/generate scaffold Todo title:string body:text done:boolean due:datetime
前几个月大家还在感叹model里面竟然可以那样sexyness,现在看看这个直接在命令行搞定,现在该用啥词形容好呢。
最后别忘记
Ruby代码
rake db:migrate
rake db:migrate
4、运行起来看看。
Ruby代码
ruby script/server
ruby script/server
然后用浏览器访问下面的链接127.0.0.1:3000/todos
搞定了一个todolist。
rails2.02快速体验 - rails - Ruby - JavaEye论坛
windows下的rails2.02环境搭建指南 - rails - Ruby - Jav...
Ruby On Rails 项目时间小结-yueguangyuan -JavaEye技术社...
RoR历险记:一个Java程序员的Ruby on Rails体验
关于REST的一点想法,欢迎大家讨论。-rails-Ruby -JavaEye做最棒的软件...
详解用radrails调试rails应用程序--Ruby -JavaEye做最棒的软件开发...
关于REST的一点想法,欢迎大家讨论。 - rails - Ruby - JavaEye论...
Ruby off the Rails
什么是Ruby on Rails
Ruby on Rails
什么是Ruby on Rails
新手RoR十分钟初体验Step By Step rails Ruby
RoR历险记:一个Java程序员的Ruby on Rails体验 - CSDN 新闻
Ruby on Rails Cheat Sheet - Ruby On Rails - ILoveJackDaniels.com
[Ruby on Rails]Vim 开发 ruby on rails 完全配置
What Is Ruby on Rails
Ruby on Rails 学习资料
Ruby on Rails 学习资料
ONLamp.com -- Rolling with Ruby on Rails
Vim 开发 ruby on rails 完全配置...
Ruby on Rails有用的插件
Vim 开发 ruby on rails 完全配置...
通过JavaEye2.0网站看ruby on rails性能-rails-Ruby -Ja...
在Linux平台上安装和配置Ruby on Rails详解-rails-Ruby