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. http://www.codeschool.com/code_tv/heroku
- 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'
$ sudo apt-get install libpq-dev postgresql
$ rails new chatty --database=postgresql
$ sudo -u postgres createuser -D -P chatty
Enter password for new role: secretpassword
Enter it again: secretpassword
Shall the new role be a superuser? (y/n) y
I had to also modify the postgresql pg_hba.conf http://blog.deliciousrobots.com/2011/12/13/get-postgres-working-on-ubuntu-or-linux-mint/
add your password
$ cd chatty
$ be rake db:create
$ be rails generate scaffold Room topic:string
invoke active_record
create db/migrate/20120715151208_create_rooms.rb
$ 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 && git add . && git commit -m "Initial commit."
Initialized empty Git repository in /Users/jay/Projects/codeschool/heroku/chatty/.git/
# On branch master
#
# 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
Change [email protected]:gentle-river-1475.git to the address given you when the command above was ran.
$ 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