Application templates in Rails 3
Rails 3 has been out for a few months now, and one of the many changes was an update to the API for generators and templates. If you’re not familiar, you’ll now use the Thor utility for these purposes, and overall the process is much more modular and customizable. Here’s how to get started.
Why would you want to use an application template, given how customizable and modular Rails 3 is? Exactly for those reasons—once you’ve figured out how you like to set up your apps, you can set them up the same way every time via a template.
I actually got started by learning how to create generators in Rails 3 (used to create custom code in an existing Rails application), then extended that to Rails templates (used to create new Rails applications, pre-baked with my favorite gem installations and other tweaks). The best resources I’ve found to date are Railscasts episodes on how generators work in Rails 3 and creating your own generators in Rails 3, followed by Thor’s documentation and the Rails guide on generators and templates.
If you want to, you can make your templates highly modular and useful for specifying gem installations from app to app. However, depending on your needs, that may be overkill. For my purposes, a single configuration has done everything I need. I’m able to quickly get an app up and running, do whatever experimentation I need to do in it, and move from there.
For the record, here’s what I’m using at the moment. Feel free to get ideas from it, or even use it as is—but I really think you’ll get more out of it if you customize it to your own preferences. Keep in mind, also, that as the tools available to me as a Rails developer change over time, my template will change. And that’s OK.
Possibly related posts
- How I learned to test my Rails applications, Part 2: Setting up RSpec (March 12, 2012)
- RVM and project-specific gemsets in Rails (September 13, 2010)
- How I learned to test my Rails applications, Part 3: Model specs (March 19, 2012)
- Moving from beginner to intermediate Rails development (July 05, 2010)
- How I learned to test my Rails applications, Part 4: Controller specs (April 07, 2012)