21 02 2008

Setting up an edge rails app

Here is my recipe for setting up a rails app, using edge rails and git.

  • Check out edge rails. I use ~/src/ext to hold source checkouts of projects which aren’t mine (mine go in ~/src)
    git clone git://github.com/rails/rails.git
  • Then create the rails app. Rails now defaults to sqlite, so if you want to use mysql you will need to pass in -dmysql to the following command:
    ruby ./ext/rails/railties/bin/rails $PROJECT
  • cd into the rails app and create a new git repository
    git init
  • To stop git from adding logs and other artefacts to the repo, create a .gitignore file in the $PROJECT folder, containing the following lines
    log/*.log
    tmp/**/*
    .DS_Store
    doc/api
    doc/app
    db/schema.rb
  • Unfortunately git won’t track folders with no content, and as we are ignoring everything in the log/ and tmp/directories, git will see them as empty and they won’t be checked out (same for other empty directories: db/ lib/ vendor/ app/models app/views but when content is added to them they will be tracked). This means that if you check out (clone) the project and run ./script/server the webserver won’t start and there will be an error saying “Rails Error: Unable to access log file”. The solution to this is to create and add a file called ’.gitignore’ to the log/ and tmp/ directories:
    touch log/.gitignore tmp/.gitignore
  • Now add all the newly created files, and commit them to the repository
    git init
    git add .
    git commit -m "empty rails project import"
  • There is now a .git/ directory in the $PROJECT folder, this folder stores the repository. I like to store my code on another machine though so I copy the repo to a remote server:
    scp -r $PROJECT_DIR user@$SERVER_IP:/desired/path/$PROJECT.git
  • The app can now be checked out from the server:
    git clone user@$SERVER_IP:/desired/path/$PROJECT.git
  • To run an app on edge rails, you need to import edge rails into vendor/rails. I use braid to track edge like so:
    braid add git://github.com/rails/rails.git vendor/rails
  • This creates a branch called braid/track which can be merged back into the current branch like so
    git merge braid/track
  • Start the server
    ./script/server

The rails app is now running on edge!

Back to Articles