heroku へのソースコード push
git push heroku master
で転送できます
次にDBの設定
これは heroku で行います
DBに関しては
Add-On で対応するので
heroku コマンドを使い、アプリに
PostgreSQL の Add-On をつける
heroku addons:add heroku-postgresql
を実行すると
DB名が
HEROKU_POSTGRESQL_SILVER_URL
となっているのでDBが使えるようになります
次にマイグレーションを実行します
heroku 側のアプリに対してコマンドを実行するには
heroku run を使います
heroku run rake db:migrate
でOK
これでブラウザからアクセスして試したいのですが
アプリのURLを忘れた場合
heroku apps:info
とすれば調べることができます
今回は
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 が動いていない可能性を考え
heroku ps:scale web=1
を実行したもののすでに
now running となっているので別の問題ということに
Procfile を確認してみたら
web: bundle exec rails server - p $PORT
となっていたのが原因
これを修正し、再度
git add . git commit -m "procfile 修正" git push heroku master
で再度転送すると、無事に稼働させることができました