Skip to content

Instantly share code, notes, and snippets.

@jackboberg
Created September 4, 2012 20:05
Show Gist options
  • Save jackboberg/3625789 to your computer and use it in GitHub Desktop.
Save jackboberg/3625789 to your computer and use it in GitHub Desktop.
RVM & Rails setup

RVM & Rails setup

System Init

Set your .gemrc to not install docs by default

# ~/.gemrc
gem: --no-rdoc --no-ri
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri

Install rvm

curl -L https://get.rvm.io | bash -s stable
rvm notes # ensure it worked

Install your first Ruby

rvm list known
rvm install 1.9.3

Convert your old gems to system gemset

rvm use system
rvm gemset export system.gems
rvm use 1.9.3
rvm gemset use global
rvm gemset empty
rvm use 1.9.3@system --default --create
rvm gemset import system.gems
rm system.gems

Set your .rvmrc to allow project based switching

# ~/.rvmrc
# enable switching to default / system when leaving a directory
rvm_project_rvmrc_default=1

Starting a new project

Create project directory and setup .rvmrc

mkdir proj && cd proj
rvm use 1.9.3@proj --create --rvmrc

Install rails

gem install --version '3.2.8' rails

Start new rails app

rails new . --skip-test-unit

Configure Rails

Update Gemfile to use explicit versions

# consult gem for current version
gem list -r sqlite3
Example Gemfile
source 'https://rubygems.org'

gem 'rails', '3.2.7'

gem 'bootstrap-sass', '2.0.4.0'
gem 'bcrypt-ruby', '3.0.1'
gem 'jquery-rails', '2.0.2'
gem 'bluecloth', '2.2.0'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.10.0'
  gem 'faker', '1.0.1'
end

group :development do
  gem 'annotate', '2.5.0'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
  gem 'compass-rails', '1.0.3'
end

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '1.4.0'
end

group :production do
  gem 'pg', '0.12.2'
end

Enable bundler without produciton

chmod +x $rvm_path/hooks/after_cd_bundler
bundle install --without production --binstubs=./bundler_stubs

Tell rails to use rspec

rails generate rspec:install

initialize git and ignore bundler_stubs

git init
echo 'bundler_stubs/' >> .gitignore

Using compass with the asset pipline

Create a compass config file

# config/compass.rb
# Require any additional compass plugins here.
project_type = :rails
additional_import_paths = ["app/assets/stylesheets/_partials",
  "app/assets/stylesheets/_plugins"]

Remove the stylesheets from the asset pipeline

  • delete application.css
  • create directories
    • app/assets/stylesheets/_partials/
    • app/assets/stylesheets/_plugins/
  • create the following files
    • application.scss
    • print.scss
    • ie.scss
Example app/assets/stylesheets/application.scss
@import 'variables';
@import 'mixins';

@import "bootstrap";
@import "bootstrap-responsive";

@import "compass/reset";
@import "compass";

// plugins
@import "jquery.noUiSlider";

// partials
@import 'typography';

Edit the default app/views/layouts/application.html.erb file

<%= stylesheet_link_tag "application", :media => "all" %>
<%= stylesheet_link_tag "print", :media => "print" %>
<!--[if IE]>
  <%= stylesheet_link_tag "ie", :media => "screen, projection" %>
<![endif]-->

Begining the Rails app

Delete the static public/index.html

Make a static pages controller

rails generate controller StaticPages home --no-test-framework

Update config/routes.rb

root :to => 'static_pages#home'

Start heroku app

heroku accounts:set topic
heroku apps:create [NAME]

Edit your .git/config

url = [email protected]:[NAME].git

Setup gitflow

git branch production
git flow init

Deploy to heroku

rake assets:precompile
git push heroku production:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment