For a long time I’ve been disappointed with the “out of the box” look and feel of a new Rails app: no useful stylesheets whatsoever, just plain unformatted text on a white background. I often like to throw together quick apps to prototype a concept, or even create a long-term app that just doesn’t need to be visually unique, but needs to look decent.
I’ve also found that every time I create a new Rails app I end up going into one of my more “established” applications and stealing whole bunches of code to bring my new app up to my standards.
Since Rails allows the creation of Application Templates, I figured it was about time I dove in and spent some time creating one of my own. This strikes me as one of those projects that will never be done but is now good enough to be very useful. My template is on GitHub at https://github.com/greendog99/greendog-rails-template along with some basic documentation to help get started.
After cloning the github repository locally (into /tmp in the example below), a new Rails app can be created by specifying the template file, like this:
rails new appname -d mysql -m /tmp/template/template.rb
A standard rails application will be created as usual, but the template will then make many changes. Some of the bigger ones are:
- Install and set up the compass-html-boilerplate gem by Peter Gumeson (sporkd). This provides:
- All templates, stylesheets, and views use haml and sass.
- Paul Irish’s HTML5 Boilerplate is installed for layout and style reset.
- Compass is installed for managing CSS mixins and frameworks.
- Adds a simple 960px 12-column grid framework from http://www.1kbgrid.com/
- Adds a basic stylesheet with header, navigation bar, body, footer, tables, forms, buttons, and flash messages, so web pages look good out of the box.
- Adds a default Gemfile with my most commonly used gems, like friendly_id.
- Creates a custom RVM gemset for the application, and installs all needed gems via bundler.
- Sets up RSpec and factory_girl for testing, instead of the default test-unit.
- Creates a Git repository and commits the entire project into version control.
There are several other smaller features that get added, which are listed in the GitHub documentation. The template also adds a couple sample views to help get started using the framework. Here’s what a brand new Rails application looks like after running the “rails new” command above: