Skip to content

Instantly share code, notes, and snippets.

@tarun-pacifica
Last active September 24, 2016 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tarun-pacifica/4ab048bd54ca56fb237e to your computer and use it in GitHub Desktop.
Save tarun-pacifica/4ab048bd54ca56fb237e to your computer and use it in GitHub Desktop.
Rails & Heroku

Deploying to Heroku using Rails

###Downloads

  • Begin by downloading and installing The Heroku Toolkit via [MacOSX] or [Ubuntu]. (If you havent done so already) (The Toolkit includes Heroku Command Line utility, as well as git and Foreman.)

  • Install the Bundler gem for Ruby. ( Learn about [Bundler] )

$ gem install bundler
  • Add rails_12factor gem to your gemfile
gem 'rails_12factor', group: :production
  • Bundle your gems
$ bundle 

... which should return something like this:

Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

###Deployment

  • Now Login to Heroku. If not created, manually create a SSH Key.
$ heroku login
Enter your Heroku credentials.
Email: adam@example.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/adam/.ssh/id_rsa.pub
  • Create a new web application
$ heroku create
Creating murmuring-galaxy-997... done, stack is cedar
http://murmuring-galaxy-997.herokuapp.com/ | git@heroku.com:murmuring-galaxy-997.git
Git remote heroku added
  • Connect your local repository to the Heroku repository
$ heroku git:remote -a murmuring-galaxy-997
Git remote heroku added.
  • Push your code to Heroku
$ git add .
$ git commit -m "first deployment to heroku"
$ git push heroku master
  • Migrate your tables. Seed if required.
$ Heroku run rake db:migrate
$ Heroku run rake db:seed
  • Check that your app has successfully deployed by reviewing status with logs
$ heroku logs

By default Heroku doesn't serve assets (eg images). Enable asset service:

#app/config/production.rb
  config.serve_static_assets = false
  config.assets.compile = false
#change these to true:
  config.serve_static_assets = true
  config.assets.compile = true

Confirm your app has deployed by viewing it in the browser

$ heroku open

Rename your app to something more userfriendly

$ heroku apps:rename newname

Further reading: [Tutorial] bundle exec rake assets:precompile [Tutorial]:http://railsapps.github.io/rails-heroku-tutorial.html [Bundler]:http:bundler.io [MacOSX]:https://toolbelt.heroku.com/ [Ubuntu]:https://toolbelt.heroku.com/

Additional commands:

$ heroku pg:reset DATABASE
$ heroku run rake db:migrate db:seed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment