Rails 3 Application Template

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:

9 Comments to “Rails 3 Application Template”

  1. Dr Zen 23 November 2010 at 4:00 am #

    Sweet! Thank you sir.

    Just starting with Rails 3 and this is gives a nice headstart.

    I’m running Ubuntu 10.10 Maverick and had one minor problem:

    Started GET “/demos/text” for at 2010-11-22 19:42:27 -0800

    LoadError (no such file to load — sqlite3):

    Adding the following line to the Gemfile cleared things right up:

    gem ‘sqlite3-ruby’, :require => ‘sqlite3′

    Great job. Thanks again.

    • Mike 27 November 2010 at 4:12 pm #

      Thanks! I always use MySQL so I had that in the Gemfile instead of Sqlite, but I forgot to add “-d mysql” to my command line in the post. It’s corrected now…

  2. Andrei 27 January 2011 at 10:09 pm #

    Hi, I’m getting
    >>Syntax error Undefined mixin ‘col’
    when I’m trying to access /demos/grid for example.
    Any clue where the mixin should be defined ?

    Thanks for this template

    • Andrei 27 January 2011 at 10:15 pm #

      Found the issue, it is named column now.

      • Andrei 27 January 2011 at 10:19 pm #

        And you also have to add @import blueprint to style.sass

  3. Mike 14 February 2011 at 2:33 pm #

    Making a lot of improvements and corrections this week to the github repo, based on two forks by others.

  4. anita 5 July 2011 at 2:17 am #

    i’m new to rails and desperately want to see it inaction outside the 3 min rail tutorial on the rails site. I have followed all the directions that come along with your template. when I navigate to it in my browser i see the directory structure in the public folder. There is no index.html. I’m sure i’m missing something. can you advise? thanks.

  5. alduro 23 September 2011 at 12:38 pm #

    Nice template ! is there a version for Rails 3.1 and assets pipeline ? Thanks in advance. Aldo

    • Mike 31 December 2011 at 10:42 pm #

      Sorry, I haven’t updated it for Rails 3.1 and probably won’t. The template seemed like a great idea at the time, but Rails and gems change too quickly between when I start each new project, and updating the template ends up not adding a lot of value over just documenting my personal bootstrapping procedure.