Rails Templates Pumped Full of Caffeine
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 http://gist.github.com/33337.txt
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...