A simple template for starting new Rails 4 projects.
This template targets the following server stack:
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
.env
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:
- Rails OS X Developer Guide – Installing an rbenv-based Rails stack on Mountain Lion
- Lightning-Fast Sass Reloading in Rails 3.2
- SMACSS and Rails – A Styleguide for the Asset Pipeline
We recommend rbenv and ruby-build for managing Ruby installations. This template currently uses Ruby 2.1.1.
- Install rbenv into
~/.rbenv
using the fantastic rbenv-installer script. - Run
rbenv install 2.1.1
(this will take several minutes). - Optional: make 2.1.1 your default ruby by running
rbenv global 2.1.1
.
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.
- Download and extract the tarball of the 55minutes/rails-starter repository; this will be the start of your new Rails project.
- Globally replace
rails-starter
andRailsStarter
with the desired name of your project. cd
into the project and rungit init && git add . && git commit -m "init"
to initialize a git repository.
- Install bundler:
gem install bundler
- Run
rbenv rehash
. - Run
bundle install
- 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.
- Run
cp example.env .env
to make a local version of the app settings. - Run
cp config/database.example.yml config/database.yml
to make a local version of the database config.
- Run
rake db:create
to initialize the database (make sure postgres is started first). - Run
rake db:migrate
. - Commit the generated schema:
git add db && git commit -m "Create schema with db:migrate"
- Run
rake spec
to make sure everything works. - Run
rails s
to start the app.
Protip: Install this handy bash script to consolidate rails
and rake
into a single r
shortcut.
The easiest way to add Twitter Bootstrap is through SimpleForm. Follow these steps:
-
Uncomment these lines in the Gemfile and run
bundle install
:gem 'simple_form' gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails'
-
Run
rails generate simple_form:install --bootstrap
-
Edit
app/assets/javascripts/application.js
and add this line afterjquery_ujs
://= require twitter/bootstrap
-
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
.
This project uses the capistrano-fiftyfive
gem, which provides all recipes needed to set up and deploy on Ubuntu 12.04. It's super simple.
Using a provider like DigitalOcean, purchase an Ubuntu 12.04 LTS virtual private server. Make sure to install your SSH key for the root user.
Make note of the IP address of the VPS. Then:
To use capistrano you will need to update the deployment settings to match your VPS.
- Review the contents of
config/deploy.rb
. Be sure the change the:repository
to match your git repository URL. - Update the IP address in
config/deploy/staging.rb
to match the IP of the VPS you just purchased. - By default,
cap production deploy
will deploy from themaster
branch, andcap staging deploy
will deploy from thedevelopment
branch. Update the branch settings if you use a different branch policy.
Don't forget to git push
your code so that capistrano can deploy it. Make sure you've pushed the branch that capistrano is expecting in staging.rb
. Then run these commands and follow the prompts to install Nginx, SSL, PostgreSQL, Ruby (the whole stack!):
cap staging provision
cap staging deploy:migrate_and_restart
Refer to the capistrano-fiftyfive README more details and deployment instructions.