This is old content! The catacombs are a snapshot of content created from 2005-2007. For new stuff, visit Maniacal Rage.

maniacal rage

Garrett Murray lives here. He's the senior developer at Blue Flavor by day and an amateur writer and comedian by night. You can read more about him or
Garrett Murray's hCard
photo

Here's how I create a new Rails app and start version control using SVN. I keep my repositories in a directory called source and I develop in a directory called rails (under the default sites folder), both in my home directory. For the purposes of this tutorial, I will be creating a new Rails project for development of this site.

This all assumes you've got Ruby, LightTPD (not required), SVN and Ruby on Rails installed. Need to install Ruby/Rails? Check out Dan Benjamin's tutorial over at Hivelogic. It's excellent. Need to install SVN? Check out Dan Benjamin's other tutorial over at Hivelogic, or you can use one of Martin Ott's pre-built packages. This also assumes you're using OS X. Most of this would apply to other platforms, but you'll have to tweak it on your own.

Of course, please be careful, et cetera, no guarantees, you know the drill with all of this. I'm just posting it here so other people can benefit from it, but I can't promise it will work for you (as always, be careful).

  1. Create an SVN repository.

    svnadmin create ~/source/maniacalrage.net
    
  2. Create a basic directory structure for the repository. I use the recommended three top level directores: branches, tags and trunk. I work out of trunk and create branches when I have stable builds. Create this structure in a temporary directory (created below) and then import it into the new repository.

    mkdir ~/temp
    mkdir ~/temp/branches
    mkdir ~/temp/tags
    mkdir ~/temp/trunk
    
  3. Do the initial import of this structure. Note that the location of the repository must be explicitly stated—you can't use ~/. Of course, all ~/ means is /users/your_user_name. Once you're done, you can trash that temporary directory you created (be careful with that rm command!).

    svn import ~/temp file:///users/garrett/source/maniacalrage.net -m "initial import"
    rm -r ~/temp
    
  4. Let's check out your local working copy. There are a couple of things to note about the checkout line—once again, you must specify the full path to your repository (and this time, include the trunk directory since that's where you'll be working from), and you need to give the checkout command the name of the folder you want your working copy to exist in. The most logical choice here is maniacalrage.net.

    cd ~/sites/rails
    svn checkout file:///users/garrett/source/maniacalrage.net/trunk maniacalrage.net
    
  5. Okay, it's time to create your Rails app. You're going to create it inside the directory you just created when checking out. Rails will simply add files to the existing directory.

    rails maniacalrage.net
    
  6. Now that we've got our Rails app in place, we need to add everything it just created to SVN. We're going to force SVN to accept all the files and directories.

    cd maniacalrage.net
    svn add . --force
    
  7. Check those files in.

    svn ci -m "initial rails import"
    svn up
    
  8. We don't want our log files versioned, so let's remove them from SVN and tell SVN to ignore them in the future. You could also ignore the database.yml file, but I never do since I always mimic my development environment's settings when I work from various machines (i.e. I use the same MySQL login and password from machine to machine).

    svn remove log/*
    svn propset svn:ignore "*.*" log/
    svn ci -m "removing log files and ignoring them in the future"
    svn up
    
  9. (If you're going to use Webrick as your local testing server, skip these last two steps—they only apply to LightTPD.) Run your Rails app for the first time and then shut it down (using control-c on the keyboard). This will create the config/lighttpd.conf file.

    ./script/server
    
  10. Add the new conf file to your repository.

    svn add config/lighttpd.conf
    svn ci -m "added lighttpd conf file"
    svn up
    

And you're done. This may seem like a lot of work, but it's actually rather trivial once you've done it once or twice. From this point on, you can begin developing your Rails app and you're all set up for version control. Where do you go from here? A few places:

  • The SVN Guided Tour.
  • SvnX is an open GUI client for Subversion and OS X. Will make several things easier on you in the long run, especially diff viewing with its bundled FileMerge integration. It's also free.

In addition to the following tutorial, you might benefit from the following points of advice:

  1. Open config/lighttpd.conf and change server.port from 3000 to 80. This will allow you to access your site from localhost rather than localhost:3000. This requires you run your local testing server a bit differently, however. First, you need to disable the built-in Apache instance running on OS X, since it runs on port 80.

    /System/Library/StartupItems/Apache/Apache stop
    

    And then you need to launch your server as such and enter your password when prompted:

    sudo ./script/server
    
  2. Add a virtual host to your hosts file to simplify development. For instance, since I'll be developing this site, I'd rather access dev.maniacalrage.net on my local box than localhost. Assuming you have TextMate installed (of course you do!) and the shell command enabled (No? Just visit "Terminal Usage..." in the Help menu in TextMate), open your hosts file for editing:

    mate /etc/hosts
    

    And then add a line after the first localhost line:

    127.0.0.1  dev.maniacalrage.net
    

    Save, enter your password when prompted, and close. Now you can view your new URL when developing and you'll get your Rails app.

Now get to work building your new Rails application, send me lots of gold, and subscribe to the podcast!

Tags: rails, svn, tutorials, webdev Hierarchy: previous, next