Summary of Commonly Used Commands and Flow for Web App Development with Heroku + Ruby on Rails 3.2
I’ve compiled commonly used commands for web app development with Heroku + Ruby on Rails 3.2 series along with the overall flow so you can understand almost everything by reading just this article. (Last updated: 2012/06/02)
If you don’t have Ruby, Rails, Heroku, and other environments set up, prepare your development environment by referring to the following:
・[Mac] Homebrew をインストール | CodeNote.net ([Mac] Install Homebrew | CodeNote.net)
・Mac OS X Lion に RVM で Ruby の開発環境を構築する手順 | CodeNote.net (Procedure to Build Ruby Development Environment with RVM on Mac OS X Lion | CodeNote.net)
・[RVM] Ruby on Rails のバージョンを管理する方法 | CodeNote.net ([RVM] How to Manage Ruby on Rails Versions | CodeNote.net)
・[Ruby][RVM] gemset global に Heroku をインストールする | CodeNote.net ([Ruby][RVM] Install Heroku in gemset global | CodeNote.net)
Create a Rails app with the rails new command, then start WEBrick (a simple HTTP server) with the rails s command and access http://localhost:3000/ to check in the browser.
rails new myapp -T
cd myapp
rails s
Create a Git repository and make the first commit.
git init
git add -A
git commit -m "create new app"
Install necessary gems.
# webserver
gem 'thin'
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
# For TDD
gem 'spork'
gem 'rspec-rails'
gem 'autotest-rails'
gem 'webrat'
gem 'cucumber'
end
After editing the Gemfile, run bundle install to organize gem dependencies and reinstall.
bundle install --without production
Create an application on heroku with the heroku create command.
If you enter a name as an argument, it will register the application with the specified name.
Also, since Rails 3.1 won’t work without the Cedar stack, you need to create the Heroku application with the —stack cedar option.
(From June 20, 2012, it seems Cedar stack is created by default.)
heroku create myapp --stack cedar
・Reference: Heroku | Dev Center | Rails 3.1 on Heroku Cedar
・Reference: Heroku | Dev Center | Getting Started with Rails 3.0 on Heroku/Cedar
Next, use Git to send the application source code to the Heroku repository of the created app.
git push heroku master
Open the created app in a browser with the heroku open command to check.
$ heroku open
Referring to this, change the web server on Heroku from WEBrick to thin.
・[Heroku] WebServer を WEBrick から thin に変更する方法 – [Rails 3.x on Heroku/Cedar] | CodeNote.net ([Heroku] How to Change WebServer from WEBrick to thin – [Rails 3.x on Heroku/Cedar] | CodeNote.net)
Configure to use heroku-postgresql:dev instead of shared database.
・[Heroku] heroku-postgresql:dev の設定方法 | CodeNote.net ([Heroku] How to Configure heroku-postgresql:dev | CodeNote.net)
Since heroku automatically generates database.yml during deployment, no particular database.yml configuration seems necessary.
git rm public/index.html
rails generate model user \\
uid:integer name:string first_name:string middle_name:string last_name:string \\
link:text username:string gender:string locale:string email:string friend_num:integer
git commit -am "create model"
heroku run rake db:migrate --app=myapp-staging
rails g controller users
Change the error screen in the staging environment to the same display as the development environment.
config/environments/staging.rb
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
Check logs in real-time:
heroku logs --tail
Start Rails console on Heroku:
heroku run console
For now, that’s all. (Will be updated as needed)
That’s all from the Gemba.