Posted by cnruby Thu, 29 May 2008 09:01:00 GMT

Rails框架讲座:如何演练Rails 2.1 RC1

目录
 (一)系统环境:

  1. Ruby 语言 1.8.6版本, 点击这里Ruby1.8.4。要想安装多个Ruby语言运行环境请看这里
  2. Rails 框架 2.0.2版本,安装方法请看这里,最简单方法是第一种方法即可。
  3. Windows XP 或者 Windows 2000操作系统 或者 Linux Ubuntu操作系统
  4. 需要一个浏览器,如FireFox1.5.0.1以上版本。
  5. 开发编辑工具 Notepad2 ,安装方法请单击这里,复制一个notepad2.exe,并且更名为vi.exe。
  6. 在Windows XP上安装Linux核心命令,点击这里
  7. 如何在Windows Console下使用命令svn(下载软件),点击这里
  8. 在Windows上安装版本控制系统Git作为客户端使用,点击这里
  9. 安装数据库系统SQLite3,点击这里

 (二)前提条件:

  1. 在本机Winodw操作系统上,我们的工作目录为d:\works_rails2008。
  2. 你的电脑必须在线。
  3. 安装Rails框架插件thin:
    gem install thin --no-ri --no-rdoc

 (三)目的:

  1. 我们想要在一个已有Rails项目(版本为2.0.2)上安装和使用Rails框架最新版本2.1 RC1,注意不改变系统上的Rails框架版本。

 (四)解决方案:

  1. 创建一个Rails项目:
    rails test_project && cd test_project
  2. 查看系统Rails框架版本,应该还是版本2.0.2。
    rails -v
  3. 查看该Rails项目的版本信息
    ruby script/about
    输出结果:
    About 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
  4. 安装Rails框架2.1 RC1到该Rails项目上
    git clone git://github.com/rails/rails.git vendor/rails
  5. 再一次查看该Rails项目的版本信息
    ruby script/about
    输出结果:
    About 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
  6. 查看该Rails项目目录script文件
    ls script
    输出结果:
    about  console  destroy  generate  performance  plugin  process  runner  server
  7. 更新该Rails项目相关到Rails2.1 RC1内容
    rake rails:update
  8. 查看该Rails项目目录script文件,发现多了一个文件dbconsole
    ls script
    输出结果:
    about    dbconsole  generate     plugin   runner console  destroy    performance  process  server
  9. 为了使用上面这个新文件dbconsole,可以使用如下命令。该命令简化和统一了打开数据库方法。
    ruby script/dbconsole
    >>.exit
  10. 再次,查看系统Rails框架版本,应该还是版本2.0.2。
    rails -v
  11. 修改该Rails的相关配置文件environment.rb
    vi config/environment.rb
    【代码开始】
    。。。
    RAILS_GEM_VERSION = '2.0.991'
    。。。
    【代码结束】
  12. 创建该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
    【代码结束】
  13. 启动网络服务器thin,或者使用Mongrel。
    thin start

 (五)视听教学:



  (六)必须注意的问题:


 (七)参考资料:

  1. Rails 2.1将会有什么

 (八)命令清单:

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:

Posted in  | Tags , , ,