Railsアプリは3.1.3、ruby 1.9.2
■各種gemのインストール
・heroku
herokuアプリを操作するherokuコマンドを利用するため必要
・pg
HerokuはデータベースがPostgreSQLなので必要。
database.ymlの設定は無視され、問答無用でPostgreを利用することになるようだ。
インストールされていないと、以下のようなエラーが出る。
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.) (RuntimeError)
・therubyracer-heroku
以下のようなエラーが出た場合はインストール。heroku createの際に--stack cedarオプションをつければ、出ないらしい(未確認)。
/app/.bundle/gems/ruby/1.9.1/gems/execjs-1.2.12/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
ちなみに、Macの場合のみインストールする
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
のようにifがあるとdevelopment,test グループであっても以下のようなエラーになるのでコメントするか削除しておく。You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
You have deleted from the Gemfile:* rb-fsevent
the resulting snapshot (Gemfile.lock) into version control
You have deleted from the Gemfile:* rb-fsevent
■Gemfile
最小限だとこんな感じに
group :development, :test do
gem 'heroku'
end
group :production do
gem "pg"
end
gem 'heroku'
end
group :production do
gem "pg"
end
■gemをインストール
bundle instal
■herokuアプリを作成
heroku create アプリ名 --stack cedar
その後Heroku登録時のメールアドレス、パスワードを入力
※アプリ名を付けない場合は適当な名前になる。その後Heroku登録時のメールアドレス、パスワードを入力
これで、https://api.heroku.com/myapps/にアプリが作成される。
remoteには自動でherokuが追加される。
■デプロイ
masterブランチをpush、マイグレーションしてopenするとブラウザが起動してアプリを表示してくれる。
git push heroku master
heroku rake db:migrate
heroku open
heroku rake db:migrate
heroku open