道喜技术日记

RCP Rails Ruby 。。。创新来自于刻苦的实践和勤奋的思考... www.hhtong.com

  • Rails框架:如何演练Rails 2.1 RC1  

    2008-05-29 09:01

    gudao.luo@gmail.com (cnruby) - Rails框架实例讲座

    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:

  • JRuby语言:《JRuby语言实战技术》预计2008年6月出版  

    2008-05-26 09:06

    gudao.luo@gmail.com (cnruby) - Ruby+JRuby

    《JRuby语言实战技术》预计2008年6月出版

  • 软件开发工具:在Windows上安装版本控制系统Git作为...  

    2008-04-10 19:20

    gudao.luo@gmail.com (cnruby) - 开发工具

    在Windows上安装版本控制系统Git作为客户端使用

  • 软件命令行解说:解决GnuWin32在Windows Vista上的问题  

    2008-03-23 22:33

    gudao.luo@gmail.com (cnruby) - 软件命令解说

    软件命令行解说:解决GnuWin32在Windows Vista上的问题

  • JRuby语言内部报道:CRuby语言和JRuby语言gem命令差异  

    2008-03-21 20:14

    gudao.luo@gmail.com (cnruby) - Ruby+JRuby

    JRuby语言内部报道:CRuby语言和JRuby语言的gem命令差异

    • 问题提出
      曾经在CRuby和JRuby语言中,命令gem install antwrap或者gem install Antwrap是一样的,但是现在JRuby语言不行了,这是因为它注意区分大小写了。
    • JRuby错误命令实例
      jruby -S gem install antwrap -r
      命令执行输出结果
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      ERROR:  could not find antwrap locally or in a repository
    • 解决方案
      jruby -S gem install Antwrap -r
      命令执行 输出结果
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Successfully installed Antwrap-0.7.0-java
      1 gem installed
      Installing ri documentation for Antwrap-0.7.0-java...
      Installing RDoc documentation for Antwrap-0.7.0-java...
    • 参考资料
      http://www.hhtong.com/blog1/articles/2007/08/06/infoq-20070806-antwrap
  • 软件命令行解说:批量转换图片文件格式  

    2008-03-09 12:39

    gudao.luo@gmail.com (cnruby) - 开发工具

    软件命令行解说:批量转换图片文件格式

  • Ruby语言:Ruby程序运行外部程序(三)  

    2008-01-26 21:53

    gudao.luo@gmail.com (cnruby) - Ruby+JRuby

    Ruby语言:Ruby程序运行外部程序(三)

    (.^.)说明:这是一个简单的Windows程序实例应用程序。在下面这个程序中,最后一行代码的函数不能使用Ruby语言的system函数。从中可以看到各种方法之间在不同的场合下存在的差异。

    (.^.)在Windows系统下启动Rails应用程序的Ruby程序。
    require 'Win32API'

    def system(cmd)
      sys = Win32API.new "crtdll", "system", ['P'], 'L'
      sys.Call cmd
    end

    system("d: && cd D:\opt\rails-app && ruby script/server")
  • Ruby语言:Ruby程序运行外部程序(二)  

    2008-01-25 21:39

    gudao.luo@gmail.com (cnruby) - Ruby+JRuby

    Ruby语言:Ruby程序运行外部程序(二)


    (.^.)说明:这里主要说明面向操作系统的程序代码

    (.^.)Windows操作系统
    require 'Win32API' 
    def system(cmd)
      sys = Win32API.new "crtdll", "system", ['P'], 'L'
      sys.Call cmd
    end

    system("del ./hello.txt")

    (.^.)Linux操作系统程序一

    require "Shell"

    sh = Shell.new
    sh.ls "-al ."
    sh.cd "/opt/java"

    (.^.)Linux操作系统程序二
    require "Shell"

    sh = Shell.new
    sh.echo("puts 'Hello World!'") > hello.rb
    sh.time("ruby hello.rb")

  • Ruby语言:Ruby程序运行外部程序(一)  

    2008-01-24 21:10

    gudao.luo@gmail.com (cnruby) - Ruby+JRuby

    Ruby语言:Ruby程序运行外部程序(一)

    (.^.)软件环境
    (.^.)函数system
    • Linux系统实例代码
      system "rm /tmp/hello.txt"
    • Windows实例代码
      system "cmd /c del ./hello.txt"
      system "calc"
    • 说明
      在执行该函数system以后,程序会继续执行之后的代码。
    (.^.)函数exec
    • Linux系统实例代码
      system "ls -al /tmp/hello.txt"
    • Windows实例代码
      system "ls -al ./hello.txt"
    • 说明
      在执行该函数exec以后,程序就停止执行之后的代码。
    (.^.)函数·
    • Windows和Linux系统实例代码
      ·ls -al .·
    • 说明
      函数·(重音符,在Tab键上面的按钮)能够让我们获得输出结果。
    (.^.)函数%x
    • Windows和Linux系统实例代码
      %x(ls -al .)
    • 说明
      注意这里的括号不能省略。
  • Ruby语言:Ruby语言1.9.0 Windows版本几点说明  

    2007-12-26 23:48

    gudao.luo@gmail.com (cnruby) - Ruby+JRuby

    Ruby语言:Ruby语言1.9.0 Windows版本几点说明

    • 说明
      • Ruby语言1.9.0是一款开发版本;
      • Ruby语言1.9.0的Windows系统mswin版本有两个版本:32位和64位;
      • Ruby语言1.9.0的Windows系统mswin版本软件,点击这里或者这里
      • Ruby语言1.9.0的Windows系统mswin版本的第三方软件,点击这里这里。一般而言这些软件包都是需要的。
      • Ruby语言1.9.0与Rails 2.0不兼容的,Rails 2.0与Ruby 1.8.6版本兼容;
    • Windows系统基本安装命令
      mkdir d:\opt\ruby1.9
      SET RUBY_HOME=d:\opt\ruby1.9
      cd d:\opt\ruby1.9
      wget ftp://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/unstable/ruby-1.9.0-0-i386-mswin32.zip
      7za x ruby-1.9.0-0-i386-mswin32.zip
      bin\ruby -v
      bin\irb
    • Windows系统第三方软件包安装方法说明
      • 下载第三方软件包,使用文件名称包含mswin32的文件,如
        wget http://jarp.does.notwork.org/win32/zlib-1.1.4-1-mswin32.zip
      • 解压该下载的软件包,如
        7za x zlib-1.1.4-1-mswin32.zip
      • 复制该软件包的bin目录下的文件至%RUBY_HOME%\bin中,如
        cp bin\. %RUBY_HOME%\bin\.
    • Windows系统第三方软件包清单
      http://jarp.does.notwork.org/win32/openssl-0.9.8d-2-mswin32.zip
      http://jarp.does.notwork.org/win32/pdcurses-2.60-1-mswin32.zip
      http://jarp.does.notwork.org/win32/readline-4.3-2-mswin32.zip
      http://jarp.does.notwork.org/win32/zlib-1.1.4-1-mswin32.zip
      http://jarp.does.notwork.org/win32/pdcurses-2.60-1-mswin32.zip
    • 参考资料