LoginSignup
25
29

More than 5 years have passed since last update.

Herokuデプロイのtips

Last updated at Posted at 2016-02-12

Heroku de Deploy

Cloud9からHerokuにデプロイするときに戸惑ったのでメモ。
環境
Cloud9 / Rails4



1:まず。ここを変更しよう

HerokuはSqliteに対応していないため、pgに変更します。
Rails/Gemfile
--Before--
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

--After--
# Use sqlite3 as the database for Active Record
gem 'sqlite3', groups: %w(test development), require: false
gem 'pg', groups: %w(production), require: false
Rail/Database.yml
--Before--
production:
  <<: *default
  database: db/production.sqlite3

--After--
production:
  <<: *default
  adapter: postgresql
  database: mydatabase

2:gitからpush

$ git add .

gitに全てを追加

$ git commit -m "first commit"

commitする

$ heroku login

[y/N]と要求されたらyを押す
あらかじめ作っておいたアカウントのID/Psを入力しログイン

$ heroku create

heroku create [アプリケーションの名前] で指定することも可

$ git push heroku master

herokuへデプロイ

To https://git.heroku.com/***.git
* [new branch] master -> master
と表示されればOK

$ heroku run rake db:migrate

herokuのdbがカラの状態なのでdbを生成

$ heroku open

アプリケーションが開く




もしもエラーが出たら

  • git push heroku masterの後、[error: failed to push some refs to ***]が出たら

DBの設定がpgになってない場合があります。
最初の設定をもう一度確認してみてください。

3:最後に。

エラーが出たりとずっとデプロイできなかったのですが、無事今回デプロイできたので、書くことにしました。
原因はdatabaseをpgに変えていなかったせいでした。
何か質問等あれば、コメントください。できる限り対応します。

参考文献
http://d.hatena.ne.jp/EnnuimaZ/20120407/1333806290
http://gam0022.net/blog/2013/09/17/run-rails4-on-heroku/
上記2つの記事を踏まえ、自己検証の上 簡潔にこの記事へまとめました。

25
29
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
29