Back To The Main Support Page

Best Practices

Slingshot Hosting and Highgroove Studios have been developing applications since early 2005 using the Ruby on Rails framework. We've developed quite a few Best Practices we'd like to share.

Slingshot Servers come ready to implement all these simple, yet effective, time-saving, tips and tricks.

Contents

Communicating through Code
Tips and Tricks

Communicating through Code

On all our projects, we use the README in the Rails root for communicating the important information about our server setups. Here's a sample from one of our latest applications:

=== Setup Instructions
WidgetFinder is a widget tracking application.

Requires gems:
 redcloth (3.0.4)
 rmagick (1.14.1)

Plugins: 
 globalize 

mysql database needs to be UTF-8 compliant.

* Create a database.yml file & the associated databases
* Run: rake globalize:setup
* Run: rake db:migrate
* Run: rake db:test:clone
* Run: rake

Capistrano reads like a recipe for deploying your app. Make it verbose. If you start with our capistrano recipe, you'll find it easy to make changes to configuration files. It's a matter of running cap setup and re-deploying.

An example:

desc Tasks to execute after code update
task :after_update_code, :roles => [:app, :db] do
  # relink shared deployment database configuration
  run ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml

  # relink shared deployment database configuration
  run ln -nfs #{deploy_to}/#{shared_dir}/config/mongrel_cluster.yml #{release_path}/config/mongrel_cluster.yml

  # relink shared tmp dir (for session and cache data)
  sudo rm -rf #{release_path}/tmp 
  run ln -nfs #{deploy_to}/#{shared_dir}/tmp #{release_path}/tmp

  # relink ferret index
  run ln -nfs #{deploy_to}/#{shared_dir}/ferret_index #{release_path}/db/ferret_index

Keep everyone up to date on code commits by using Subversion's built in post-commit hooks. For more information, see Version Control with Subversion: Chapter 5: Hook Scripts.

Grab the latest post-commit scripts here:

$ cd /var/svn/repos/my_repo/hooks
$ curl -O http://svn.highgroove.com:8080/deployment/trunk/post-commit
$ curl -O http://svn.highgroove.com:8080/deployment/trunk/commit-email.pl
$ chmod +x post-commit
$ chmod +x commit-email.pl

Edit the $REPO_NAME variable and setup an e-mail forward to your development team. Remember, the more people are in the loop, the more it forces you to write more cohesive, readable, maintainable log messages.