Create a new Edge Rails project
In a previous post, I provided scripts that made the creation of a new Edge Rails project easy. Since then, Rails has moved from Subversion to Git, which means that the scripts I provided no longer work as expected. Fortunately, very little has changed and I was able to make the script a little bit better so that it acts like the original rails command.
Prerequisites
First, you’re going to need git. I could have written the script to grab the latest version via a zipfile, but I wanted something that was fast and worked on all platforms. Windows can unzip files, but then I’d have to make Windows users go grab commandline tools to unzip files.
Installing Git
Mac users with XCode and Macports installed can do it with
sudo port install git-core +svn
Windows users can install Msysgit.
Linux users should install Git using their package manager or from source.
Here’s the script. Instructions for running it are after the code.
#!/bin/ruby git_repo = "git://github.com/rails/rails.git" help = %Q{ Rails Info: -v, --version Show the Rails version number and quit. -h, --help Show this help message and quit. General Options: -p, --pretend Run but do not make any changes. --force Overwrite files that already exist. -s, --skip Skip files that already exist. -q, --quiet Suppress normal output. -t, --backtrace Debugging: show backtrace on errors. Description: The 'edge_rails' command creates a new Rails application with a default directory structure and configuration at the path you specify, using the very latest version of Rails. Example: edge_rails ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog. See the README in the newly created application to get going. } require 'fileutils' if ARGV.empty? puts help exit end dir = ARGV.shift args = ARGV.join (" ") FileUtils::mkdir(dir) FileUtils::mkdir("#{dir}/vendor") puts "Exporting EdgeRails from #{git_repo}" # system "svn export http://svn.rubyonrails.org/rails/trunk #{dir}/vendor/rails" system "git clone --depth=1 #{git_repo} #{dir}/vendor/rails" system "rm -rf #{dir}/vendor/rails/.git*" system "ruby #{dir}/vendor/rails/railties/bin/rails #{dir} #{args}"
How this works for Mac and Linux users
Save the script to your home folder as edge_rails, and set the execute bit:
chmod 644 ~/edge_rails
Run it with
~/edge_rails your_app
You could symlink it to your /usr/local/bin if you are feeling clever.
How this works for the Windows crowd
Save this script as c:\ruby\bin\edge_rails.bat
@echo off goto endofruby #!/bin/ruby git_repo = "git://github.com/rails/rails.git" help = %Q{ Rails Info: -v, --version Show the Rails version number and quit. -h, --help Show this help message and quit. General Options: -p, --pretend Run but do not make any changes. --force Overwrite files that already exist. -s, --skip Skip files that already exist. -q, --quiet Suppress normal output. -t, --backtrace Debugging: show backtrace on errors. Description: The 'edge_rails' command creates a new Rails application with a default directory structure and configuration at the path you specify, using the very latest version of Rails. Example: edge_rails ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog. See the README in the newly created application to get going. } require 'fileutils' if ARGV.empty? puts help exit end dir = ARGV.shift args = ARGV.join (" ") FileUtils::mkdir(dir) FileUtils::mkdir("#{dir}/vendor") puts "Exporting EdgeRails from #{git_repo}" # system "svn export http://svn.rubyonrails.org/rails/trunk #{dir}/vendor/rails" system "git clone --depth=1 #{git_repo} #{dir}/vendor/rails" system "rm -rf #{dir}/vendor/rails/.git*" system "ruby #{dir}/vendor/rails/railties/bin/rails #{dir} #{args}" __END__ :endofruby "%~d0%~p0ruby" -x "%~f0" %*
Now, open a new command prompt and type
edge_rails my_new_app
If it doesn’t work, check that you have Git installed properly and have added Git’s command line utilities to your path.
For OSX: Installer packages are also available here:
http://code.google.com/p/git-osx-installer/
I had to change:
> git clone –depth=1
to:
> git clone –depth 1
(git version 1.5.3.7; OSX)
Great post, thanks for the info