Heroku is a simple way to publish your Rails app, and a powerful platform that will allow it to scale. In this episode, Jay McGavren gets you started with your first Heroku app.
-
You WANT Rails to fail locally if a gem isn't in your Gemfile
-
Otherwise you're in for a surprise when it's missing on Heroku
$ alias be='bundle exec'
$ rails new chatty --database=postgresql
$ be rake db:create
$ be rails generate scaffold Room topic:string
$ be rake db:migrate
== CreateRooms: migrating ====================================================
-- create_table(:rooms)
NOTICE: CREATE TABLE will create implicit sequence "rooms_id_seq" for serial column "rooms.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "rooms_pkey" for table "rooms"
-> 0.1256s
== CreateRooms: migrated (0.1258s) ===========================================
$ git init
Initialized empty Git repository in /Users/jay/Projects/codeschool/heroku/chatty/.git/
$ git commit -am "Initial commit."
https://toolbelt.herokuapp.com/
$ heroku login
Enter your Heroku credentials.
Email: [email protected]
Password:
Authentication successful.
$ heroku create --stack cedar
Creating gentle-river-1475... done, stack is cedar
http://gentle-river-1475.herokuapp.com/ | [email protected]:gentle-river-1475.git
Git remote heroku added
$ cat .git/config
[core]
...
[remote "heroku"]
url = [email protected]:gentle-river-1475.git
fetch = +refs/heads/*:refs/remotes/heroku/*
$ git push heroku master
$ open http://gentle-river-1475.herokuapp.com/
$ heroku ps
$ heroku logs
$ heroku run rake db:migrate
$ heroku run console
gem 'aws-s3'
<video controls width="512" height="288">
<source
src="<%= AWS::S3::S3Object.url_for('demo.mp4', 'codetv-heroku1') %>"
type="video/mp4"
/>
</video>
config/initializers/s3.rb
require 'aws/s3'
AWS::S3::Base.establish_connection!(
:access_key_id => 'THISISSUPPOSEDTOBESECRET',
:secret_access_key => 'DONTCOMMITTHISTOGITNOMATTERWHAT'
)
config/initializers/s3.rb
require 'aws/s3'
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
)
$ heroku config:add S3_KEY=THISISSUPPOSEDTOBESECRET
$ heroku config:add S3_SECRET=DONTCOMMITTHISTOGITNOMATTERWHAT
$ heroku apps
gentle-river-1475
$ heroku destroy gentle-river-1475
! WARNING: Potentially Destructive Action
! This command will affect the app: gentle-river-1475
! To proceed, type "gentle-river-1475" or re-run this command with --confirm gentle-river-1475
> gentle-river-1475
Heroku's Rails tutorial: https://devcenter.heroku.com/articles/rails3
Installing Postgresql: https://devcenter.heroku.com/articles/local-postgresql