55minutes/ninefold-example

A simple template for starting new Rails 4 projects.

This template targets the following server stack:

  • Ubuntu 12.04 LTS
  • PostgreSQL
  • Unicorn
  • Nginx
  • rbenv
  • Postmark for mail delivery

By using this template, you’ll hit the ground running with best practices for productive Rails and front-end development:

  • RSpec and Capybara for testing
  • guard-livereload for fast, iterative front-end development
  • Up-to-date rbenv and bundler gem management techniques
  • SMACSS for organizing stylesheets
  • Capistrano recipes to make deployment easy
  • secrets.yml for storing encryption keys and secret tokens safely outside of source control
  • An easy way to add Twitter Bootstrap, should you choose to do so

More on our blog:

Getting started

Install rbenv

We recommend rbenv and ruby-build for managing Ruby installations. This template currently uses Ruby 2.0.0-p247.

  1. Install rbenv into ~/.rbenv using the fantastic rbenv-installer script.
  2. Run rbenv install 2.0.0-p247 (this will take several minutes).
  3. Optional: make 2.0.0-p247 your default ruby by running rbenv global 2.0.0-p247.

Install Qt

This starter uses the capybara-webkit gem, which requires the Qt libraries (version 4.8 or higher). These libraries aren't installed out of the box on most systems, including Mac OS X.

To install the Qt libraries, follow these instructions. Homebrew is the easiest option on the Mac.

Create a Rails project from the template

  1. Download and extract the tarball of the 55minutes/ninefold-example repository; this will be the start of your new Rails project.
  2. Globally replace ninefold-example and NinefoldExample with the desired name of your project.
  3. cd into the project and run git init && git add . && git commit -m "init" to initialize a git repository.

Bundle the required gems

  1. Install bundler: gem install bundler
  2. Run rbenv rehash.
  3. Run bundle install
  4. Once more, run rbenv rehash.

Protip: Install rubygems-bundler so you won’t need to use bundle exec all the time. Don’t forget to reinstall it whenever you install a new version of Ruby.

Set up your local configuration

  1. Run cp config/secrets.example.yml config/secrets.yml to make a local version of the secret settings.
  2. Run cp config/database.example.yml config/database.yml to make a local version of the database config.

Create the database

  1. Run rake db:create to initialize the database (make sure postgres is started first).
  2. Run rake db:migrate.
  3. Commit the generated schema: git add db && git commit -m "Create schema with db:migrate"

Run it!

  1. Run rake spec to make sure everything works.
  2. Run rails s to start the app.

Protip: Install this handy bash script to consolidate rails and rake into a single r shortcut.

Twitter Bootstrap integration

The easiest way to add Twitter Bootstrap is through SimpleForm. Follow these steps:

  1. Uncomment these lines in the Gemfile and run bundle install:

     gem 'simple_form'
     gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails'
    
  2. Run rails generate simple_form:install --bootstrap

  3. Edit app/assets/javascripts/application.js and add this line after jquery_ujs:

     //= require twitter/bootstrap
    
  4. Edit app/assets/stylesheets/application.css.scss and add these lines:

     //= require twitter/bootstrap
     //= require twitter/bootstrap-responsive
    

Twitter Bootstrap’s JavaScripts and CSS will now be available throughout your app. To create forms that use Bootstrap’s styling, use SimpleForm like this:

<%= simple_form_for(@article, :html => { :class => 'form-horizontal' }) do |f| %>
  ...
<% end %>

Protip: Here are a bunch of great SimpleForm+Bootstrap examples.

Protip: If you plan on using Devise, make sure you install SimpleForm first! Then when you install Devise, it will automatically detect SimpleForm and generate its views with simple_form_for.

Using the provided Capistrano recipes

This project uses the capistrano-fiftyfive gem, which provides all recipes needed to set up and deploy on Ubuntu 12.04. It's as easy as:

cap deploy:install
cap deploy:setup
cap deploy:cold

Refer to the capistrano-fiftyfive README more details and deployment instructions.