RailsアプリをHerokuにアップしてみる

RailsでHello, world!を表示してみる

CentOSにHerokuをインストールしてみる
の続き

RailsアプリをHerokuにアップしてみる。

【参考】
Rails Girls - Japanese
http://railsgirls.jp/heroku/

Herokuにアップ

$ cd sample

gitのリポジトリを作成する。

$ git init
$ git add .
$ git commit -m 'first commit'

Herokuのアプリを作成。

$ heroku create

プッシュする。

$ git push heroku master

しかし、エラーがでる。

 !
 !     Failed to install gems via Bundler.
 !
 !     Detected sqlite3 gem which is not supported on Heroku.
 !     https://devcenter.heroku.com/articles/sqlite3
 !

データベースの設定を修正

sqlite3はHerokuでは使えないので、下記のように修正する。

$ vi Gemfile
#gem 'sqlite3'
group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end

Gemfile.lockに反映するためにbundle install

$ bundle install --without production

Herokuにアップする。今度はうまくいった。

$ git add .
$ git commit -m 'fix'
$ git push heroku master
・・・
       http://damp-atoll-9410.herokuapp.com/ deployed to Heroku
・・・

確認

アクセスするとHello, worldと表示される。