Rails框架:如何演练Rails 2.1 RC1
Posted by cnruby Thu, 29 May 2008 09:01:00 GMT
Rails框架讲座:如何演练Rails 2.1 RC1
目录
(一)系统环境:
- Ruby 语言 1.8.6版本, 点击这里Ruby1.8.4。要想安装多个Ruby语言运行环境请看这里。
- Rails 框架 2.0.2版本,安装方法请看这里,最简单方法是第一种方法即可。
- Windows XP 或者 Windows 2000操作系统 或者 Linux Ubuntu操作系统
- 需要一个浏览器,如FireFox1.5.0.1以上版本。
- 开发编辑工具 Notepad2 ,安装方法请单击这里,复制一个notepad2.exe,并且更名为vi.exe。
- 在Windows XP上安装Linux核心命令,点击这里。
- 如何在Windows Console下使用命令svn(下载软件),点击这里。
- 在Windows上安装版本控制系统Git作为客户端使用,点击这里。
- 安装数据库系统SQLite3,点击这里。
(二)前提条件:
- 在本机Winodw操作系统上,我们的工作目录为d:\works_rails2008。
- 你的电脑必须在线。
- 安装Rails框架插件thin:
gem install thin --no-ri --no-rdoc
(三)目的:
- 我们想要在一个已有Rails项目(版本为2.0.2)上安装和使用Rails框架最新版本2.1 RC1,注意不改变系统上的Rails框架版本。
(四)解决方案:
- 创建一个Rails项目:
rails test_project && cd test_project - 查看系统Rails框架版本,应该还是版本2.0.2。
rails -v - 查看该Rails项目的版本信息
输出结果:ruby script/aboutAbout your application's environment
Ruby version 1.8.6 (i386-mswin32)
RubyGems version 1.1.1
Rails version 2.0.2
Active Record version 2.0.2
Action Pack version 2.0.2
Active Resource version 2.0.2
Action Mailer version 2.0.2
Active Support version 2.0.2
Application root E:/coding/work_rails2008/test_project
Environment development
Database adapter sqlite3 - 安装Rails框架2.1 RC1到该Rails项目上
git clone git://github.com/rails/rails.git vendor/rails - 再一次查看该Rails项目的版本信息
输出结果:ruby script/aboutAbout your application's environment
Ruby version 1.8.6 (i386-mswin32)
RubyGems version 1.1.1
Rails version 2.0.991
Active Record version 2.0.991
Action Pack version 2.0.991
Active Resource version 2.0.991
Action Mailer version 2.0.991
Active Support version 2.0.991
Edge Rails revision 4d248543429918bc5a63e109e6f2327ffab9848b
Application root E:/coding/work_rails2008/test_project
Environment development
Database adapter sqlite3
Database schema version 0 - 查看该Rails项目目录script文件
输出结果:ls scriptabout console destroy generate performance plugin process runner server - 更新该Rails项目相关到Rails2.1 RC1内容
rake rails:update - 查看该Rails项目目录script文件,发现多了一个文件dbconsole
输出结果:ls scriptabout dbconsole generate plugin runner console destroy performance process server - 为了使用上面这个新文件dbconsole,可以使用如下命令。该命令简化和统一了打开数据库方法。
ruby script/dbconsole
>>.exit - 再次,查看系统Rails框架版本,应该还是版本2.0.2。
rails -v - 修改该Rails的相关配置文件environment.rb
vi config/environment.rb
【代码开始】
。。。
RAILS_GEM_VERSION = '2.0.991'
。。。
【代码结束】 - 创建该Rails的相关配置文件new_defaults.rb
vi config/initializers/new_defaults.rb
【代码开始】
# These settins change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Only save the attributes that have changed since the record was loaded.
ActiveRecord::Base.partial_updates = true
# Include ActiveRecord class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Use ISO 8601 format for JSON serialized times and dates
ActiveSupport.use_standard_json_time_format = true
# Don't escape HTML entities in JSON, leave that for the #json_escape helper
# if you're including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false
【代码结束】 - 启动网络服务器thin,或者使用Mongrel。
thin start
(五)视听教学:
(六)必须注意的问题:
- 可能出现的问题之一:
http://ar-code.lighthouseapp.com/projects/34/tickets/166-cannot-bootstrap-undefined-method-register_template_handler-for-actionview-base-class
实例代码:
源代码 ActionView::Base::register_template_handler :liquid, LiquidView 修改为: ActionView::Template::register_template_handler :liquid, LiquidView
(七)参考资料:
(八)命令清单:
rails test_project && cd test_project
rails -v
ruby script/about
git clone git://github.com/rails/rails.git vendor/rails
ruby script/about
ls script
rake rails:update
ls script
ruby script/dbconsole
.exit
rails -v
vi config/environment.rb
【代码开始】
。。。
RAILS_GEM_VERSION = '2.0.991'
。。。
【代码结束】
vi config/initializers/new_defaults.rb
【代码开始】
# These settins change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Only save the attributes that have changed since the record was loaded.
ActiveRecord::Base.partial_updates = true
# Include ActiveRecord class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Use ISO 8601 format for JSON serialized times and dates
ActiveSupport.use_standard_json_time_format = true
# Don't escape HTML entities in JSON, leave that for the #json_escape helper
# if you're including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false
【代码结束】
thin start
(九)下载文件pdf:
________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。




![Validate my RSS feed [Valid RSS]](/blog1/files/valid-rss.png)




