Skip to content

Instantly share code, notes, and snippets.

Created June 30, 2012 21:03
  • Star 75 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save peter/3025502 to your computer and use it in GitHub Desktop.
Creating and Deploying an EdgeRails (Rails 4) Application to Heroku
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it
gem install bundler
# 1. Get edge Rails source (master branch)
git clone
# 2. Create the rails app
# The --edge option will point the Gemfile to rails on github (the tip of the master branch, i.e. EdgeRails)
# Use the --dev option to insated point your Gemfile to your local rails checkout (useful for experimentation)
rails/railties/bin/rails new myapp --edge --skip-bundle --database=postgresql --skip-test-unit --skip-index-html
# 3. (Optional) Create rvm gemset on Ruby 1.9.3 (Rails 4 requires Ruby 1.9.3)
# This step will isolate the gem dependencies of the app from other gems installed on your system
rvm --rvmrc --create 1.9.3@myapp
# 4. (Optional) Install gem dependencies and put binaries under ./bin
# If you skip this step you need to prefix commandline commands with "bundle exec"
# NOTE: I had to do the following on my mac for the gcc compiler to be found when the json gem was installed:
# sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
bundle install --binstubs
# 5. Set up PostgreSQL database
createuser myapp
bin/rake db:create
# 6. Scaffold some model to test that the app works
bin/rails generate scaffold Post title:string body:text
bin/rake db:migrate
bin/rails server
# Add root to: 'posts#index' in config/routes.rb
open http://localhost:3000
# 7. Create repo on github
# Browse to to click the "New repository" button
git init
git add .
git commit -m "First commit"
git remote add origin # use the URL from github here
git push -u origin master
# 8. Deploy to Heroku
gem install bundler --pre # Needed to specify ruby 1.9.3 for Heroku
# Add gem 'thin' to Gemfile # Typical web server for Heroku deploy
# Add ruby '1.9.3' to Gemfile (after the source directive)
# Add config.assets.initialize_on_precompile = false to config/application.rb # Avoid db connect on asset precompile
RAILS_ENV=production bin/rake assets:precompile
# (See for more info)
# NOTE: to get eventmachine (thin dependency) to install on my Mac (Mountain Lion) I had to do:
# sudo ln -s /usr/bin/llvm-g++-4.2 /usr/bin/g++-4.2
# See:
bundle install
echo "web: bundle exec rails server thin -p \$PORT -e \$RACK_ENV" > Procfile
git add .; git commit -m "Preparations for Heroku deploy"; git push
heroku apps:create peter-myapp # myapp was taken...
git push heroku master
heroku run rake db:migrate
heroku restart
heroku apps:open
heroku logs --tail
Copy link

Also worth noting: In some circumstances, you may get an error about railties not being found in the to_spec method; running bundle install --binstubs solves this.

Copy link

@Kabniell FYI I found this gist via google and you've posted your database credentials in your last comment. May want to edit them out.

Copy link

The above proposed fixes didn't work for me, but turning on this lab feature did:

Not sure I like this solution, but it's good for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment