Heroku に Ruby 2.0 + Rails 4.0beta1 をデプロイ

久々に heroku で簡単な Web アプリを作成しようと思ってどうせなら 最新バージョンでやろうと Ruby 2.0 + Rails 4.0 にした。 Rails に関しては 4.0beta1 である。

単純に deploy しただけでは Ruby 2.0 を使ってくれず、しかも 1.9.2 を使用していたみたいで、 Rails のインストールすらできなかった。 以下に方法を示す。

heroku ツールをインストール

gem i heroku を実行したところ、heroku toolbelt を推奨されたので以下のサイトからダウンロードしてインストール。

https://toolbelt.heroku.com/

ローカルで作成

Rails アプリを作成
# test は作成せず、 bundle install を実行しない
$ rails new heroku_app -T --skip-bundle
Gemfile の調整
# heroku 上 で Ruby 2.0 を使う
ruby '2.0.0'

# 開発時のみ sqlite
group :development do
  gem 'sqlite'
end

# プロダクションのみ postgres
group :production do
  gem 'pq'
end
各種コマンドの実行
$ git init
$ heroku create [app_name]
$ bundle install --without production
$ rake db:migrate
$ git add .
$ git commit -m 'first commit'

heroku へデプロイ

push と migration
$ git push heroku maseter
$ heroku run rake db:migrate

これで無事に動くはずである。

Gemfile に ruby '2.0.0' だけを忘れないようにしよう。