This is how I actually got all this stuff to work together. It'll attrophy over time but as of June 2013 it works. Maybe I'll keep it up to date.
Generally, this document is a a mashup of the following tutorials and pages...
- Getting Started with Rails 3.x on Heroku
- Rails Girls Guides -- Adding Authentication with Devise
- Agile Web Development With Rails
For me this boiled down to the following and I didn't do the symlink part.
sudo cp /Applications/Postgres.app/Contents/MacOS/lib/libcrypto.1.0.0.dylib /usr/lib
sudo cp /Applications/Postgres.app/Contents/MacOS/lib/libssl.1.0.0.dylib /usr/lib
brew install gnu-sed # this is because osx's sed is lame
Here we set up our project name, directory name and heroku project name ($PROJ.heroku.com). They don't all have to the same, but it is convenient.
export PROJ=mobgame
cd ~/Projects/bettracker/rails # you might choose differently
rails new $PROJ -d postgresql
cd $PROJ
cat <<EOF >>.gitignore
/public/assets/
.DS_Store
*~
/vendor/bundle
/.idea
EOF
git init
git add .
git commit -m 'rails new $PROJ -d postgresql && cd $PROJ && update .gitignore'
psql -c "create role $PROJ login createdb" # http://stackoverflow.com/a/8639649/9648
rake db:create
(cd tmp && wget http://twitter.github.io/bootstrap/assets/bootstrap.zip) && unzip tmp/bootstrap.zip -d public && rm -f tmp/bootstrap.zip
git add . && git commit -m "install bootstrap"
psql -c "\list" # look for $PROJ in left col. Ctc means user can Connect Create & create Temp
psql -c "\du" # shows users
rails generate scaffold Venue title:string address:string image_url:string
rake db:migrate
git add . && git commit -m "rails generate scaffold Venue"
gsed -i '/welcome#index/a\ root :to => redirect("/venues")' config/routes.rb
git rm public/index.html
git add . && git commit -m "Redirect root to /venues"
cat <<EOF >> Gemfile
#Use devise for auth
gem 'devise'
EOF
bundle install
git add . && git commit -m "Add 'devise' to Gemfile && bundle install"
rails generate devise:install
git add . && git commit -m "rails g devise:install"
You'll get the following output:
Some setup you must do manually if you haven't yet:
-
Ensure you have defined default url options in your environments files. In production, :host should be set to the actual host of your application. Here is an example of default_url_options appropriate for a development environment in config/environments/development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
-
Ensure you have defined root_url to something in your config/routes.rb. For example:
root :to => "home#index"
-
Ensure you have flash messages in app/views/layouts/application.html.erb. For example:
<p class="notice"><%= notice %></p> <p class="alert"><%= alert %></p>
-
If you are deploying Rails 3.1+ on Heroku, you may want to set the following on config/application.rb forcing your application to not access the DB or load models when precompiling your assets:
config.assets.initialize_on_precompile = false
-
You can copy Devise views (for customization) to your app by running:
rails g devise:views
Define default URL in our development & production environments.
gsed -i 's/^end$/ config.action_mailer.default_url_options = { :host => "localhost:3000" }\nend/' config/environments/development.rb
gsed -i 's/^end$/ config.action_mailer.default_url_options = { :host => "'$PROJ.herokuapp.com'" }\nend/' config/environments/production.rb
git add . && git commit -m "config.action_mailer.default_url_options"
Add notice and alert flashes to app/views/layouts/application.html.erb
gsed -i '/<%= yield %>/s~.*~<% if notice %>\n <p class="alert alert-notice"><%= notice %></p>\n<% end %>\n<% if alert %>\n <p class="alert alert-error"><%= alert %></p>\n<% end %>\n<%= yield %>~' app/views/layouts/application.html.erb
git add . && git commit -m "notice and alert flashes"
Don't access the DB or load models when precompiling assets:
gsed -i '/^ end$/i\ config.assets.initialize_on_precompile = false' config/application.rb
git add . && git commit -m "config.assets.initialize_on_precompile = false"
rails g devise User
rake db:migrate
git add . && git commit -m "rails g devise User && rake db:migrate"
psql ${PROJ}_development -c "\dt" # show it
heroku create $PROJ
git push heroku master
heroku ps:scale web=1
heroku run rake db:create
heroku run rake db:migrate
heroku run rake db:seed
open http://$PROD.herokuapp.com
rake db:drop
psql -c "drop user $PROJ"
heroku destroy $PROJ #--confirm $PROJ # get rid of the 1st
heroku logs # show me the logs