The Kai Way

Pragmaticly hacking

体验Rails 2.1.rc1

| Comments

无须升级整个系统的Rails,只需要在项目中的Rakefile中加入下面的代码,然后运行rake rails:freeze:edge:

namespace :rails do
  namespace :freeze do
    desc 'Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0'
    task :edge do
      require 'open-uri'
      version = ENV["RELEASE"] || "edge"
      target = "rails_#{version}.zip"
      url = "http://dev.rubyonrails.org/archives/#{target}"

      chdir 'vendor' do
        puts "Downloading Rails from #{url}"
        File.open('rails.zip', 'wb') do |dst|
          open url do |src|
            while chunk = src.read(4096)
            dst << chunk
          end
        end
      end

      puts 'Unpacking Rails'
      rm_rf 'rails'
      `unzip rails.zip`
      %w(rails.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner|
        rm_f goner
      end
    end

    puts 'Updating current scripts, javascripts, and configuration settings'
    Rake::Task['rails:update'].invoke
    end
  end
end

这段代码其实是Rails2.1里的rails:freeze:edeg的Rake任务代码,因为Rails的代码库已经迁移至github,好像svn不提供新的版本,现在获取Rails最新版本的方法一是到github那里clone下来,要么就到http://dev.rubyonrails.org/archives/%E4%B8%8B%E8%BD%BD%E4%B8%80%E4%B8%AA%E6%89%93%E5%8C%85%E5%A5%BD%E7%9A%84zip%E6%96%87%E4%BB%B6%E3%80%82

其实最傻瓜的方法就是直接下载http://dev.rubyonrails.org/archives/rails_edge.zip%E7%84%B6%E5%90%8E%E8%A7%A3%E5%8E%8B%E5%88%B0vendor/%E9%82%A3%E9%87%8C%EF%BC%8C%E5%85%B6%E5%AE%9E%E4%B8%8A%E9%9D%A2%E8%B4%B4%E7%9A%84rake%E8%84%9A%E6%9C%AC%E4%B9%9F%E6%98%AF%E5%81%9A%E4%BA%86%E8%BF%99%E4%B8%AA%E4%BA%8B%E6%83%85:-)