New to Rails 3? Check out the Ruby on Rails 3 Tutorial book and screencast.

A book and screencast series showing you how to develop and deploy industrial-strength Rails apps in a direct, step by step way. The screencast series includes 12 lessons over more than 15 hours! Get the best "over the shoulder" experience of following what a top Rails 3 developer does when building an app today. Click here to learn more.

Rails Templates Pumped Full of Caffeine

In Tips

Rails 2.3 is not yet released but has become extremely popular to use already in its "edge" form. The official release will be available in the next couple of weeks (so I am told) and one of the most exciting features is "Rails templates", a feature (originally developed by Jeremy McAnally) that allows you to quickly generate a new Rails project that uses various gems, plugins, and that even has a customized file layout. You can automatically get a Git repository set up, perform other system commands and, yes, a "lot more." If templates are still new to you, read this illustrative blog post by core team member Pratik Naik.

As a proudly "lazy" developer, I saw Rails templates as being a "killer" feature for Rails. No longer would it be a chore to set up a new project, set up a git repository, and all that. I could script it! So last month I wrote the Super Daring App Template that does the following:

  • Symlink a local copy of edge Rails to vendor/rails
  • Delete the README file and various public/ files
  • Download jQuery
  • Set up a Git repository and add all files
  • Copy config/database.yml to config/database.yml.example
  • Set up .gitignore files in the relevant places
  • Install some gems
  • Create a migration for session storage in the database
  • Generate RSpec helpers
  • Run rake tasks for migrations, open ID authentication, and acts_as_taggable
  • Generate a session key and store it in an initializer
  • Initialize Git submodules
  • Commit all work to the Git repo

Then I could simply create a new Rails project like so:

rails [whatever] -m

Awesome - so it was with much delight that James Cox (a.k.a. imajes) introduced me to his sllightly more formal "rails-template" project on Github. James has taken the Super Daring App Template and enhanced it in a number of key ways. It asks questions on what you want to be installed or not installed, and even generates an initial model for you. James also came up with the idea of using a command prompt alias so that the rails command uses his new template by default. Check it out!

Even though James' template is far more customizable than mine - simply due to it asking questions - it's still going to be essential for you to customize and make your own templates. We all have our own preferences regarding testing frameworks, tagging libraries, and so forth, so one size will never fit all. If you fancy yet more inspiration on making these "everything including the kitchen sink" type templates, check out this blog post by Andrew Timberlake too.

Support from: Brightbox; - Europe's leading provider of Ruby on Rails hosting. Now with Phusion Passenger support, each Brightbox server comes with access to a managed MySQL cluster and redundant SAN storage. Brightbox also provides managed services for large scale applications and dedicated clusters.  — Special Offer: 50% off all new Brightboxes! For a limited period, get a Brightbox from £19.50 a month...

Post to Twitter Tweet This Post

Vaguely Related Posts (Usually)

3 Comment Responses to “Rails Templates Pumped Full of Caffeine”

  1. #1
    Stephan Wehner Says:

    Would it make sense to turn this tool in to a web app :-)


  2. #2
    Peter Cooper Says:

    I wondered that briefly when I wrote the first template, but then forgot all about it till you just mentioned it again :) Yes, in theory you could design something that generated the templates perhaps from a form with multiple choice questions. Choose a tagging library, choose a model, choose a templating library, etc, etc..

  3. #3
    Timothy Johnson Says:

    Aw Peter, a truly lazy programmer would have scripted this process a long time ago. Of course it depends on how many fresh-starts you get in your line of work. :)

    This is a really great DSL for doing this though, so I fully think it is a big win. The most intriguing thing for me is seeing what other people publish. I would love to know the templates and starting places for companies like hash-rocket, pivotal, thought-bot, and others.

    As much as scaffolding gets a bad rap for production sites. I find it immensely useful for administrative apps. I had to start all this scripting nonsense a while ago when I wanted to replace the built-in scaffolding with something better. I ended up forking Ryan Bates's scaffolding plugin to generate my preferred set and features.

Leave a Reply