heroku へのソースコード push
1 | git push heroku master |
で転送できます
次にDBの設定
これは heroku で行います
DBに関しては
Add-On で対応するので
heroku コマンドを使い、アプリに
PostgreSQL の Add-On をつける
1 | heroku addons:add heroku-postgresql |
を実行すると
DB名が
HEROKU_POSTGRESQL_SILVER_URL
となっているのでDBが使えるようになります
次にマイグレーションを実行します
heroku 側のアプリに対してコマンドを実行するには
heroku run を使います
1 | heroku run rake db:migrate |
でOK
これでブラウザからアクセスして試したいのですが
アプリのURLを忘れた場合
1 | heroku apps:info |
とすれば調べることができます
今回は
1 2 3 4 5 6 7 8 9 10 | Addons: heroku-postgresql:hobby-dev heroku-postgresql:hobby-dev Dynos: web: 1 Git URL: https: //git .heroku.com /shrouded-chamber-59024 .git Owner: snowpoollovely@gmail.com Region: us Repo Size: 37 KB Slug Size: 45 MB Stack: cedar-14 Web URL: https: //shrouded-chamber-59024 .herokuapp.com/ |
となりました
これでアクセスしたものの
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
となりエラーになります
heroku が動いていない可能性を考え
1 | heroku ps :scale web=1 |
を実行したもののすでに
now running となっているので別の問題ということに
Procfile を確認してみたら
1 | web: bundle exec rails server - p $PORT |
となっていたのが原因
これを修正し、再度
1 2 3 | git add . git commit -m "procfile 修正" git push heroku master |
で再度転送すると、無事に稼働させることができました