routes.rbの内容を間違えたままherokuにデプロイしたのでやり直してみた
10章まで終わったものの、herokuにデプロイできてないとメールのテストができなさそうなので、Ruby on Rails Tutorialの第3章をNitrous.ioでやり直し。
実行。
しかし、いざherokuを確認してみると、
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
If you are the application owner check the logs for more information.
というエラーが出てしまっている。
herokuのログを「Activity」から確認する。
ArgumentError: Missing :controller key on routes definition, please check your routes.
というエラーが出ている。
ググる。
「
routes.rb
ファイルを確認して:controller
の指定がおかしくないかを確認してください。」確認してみる。
あ、おかしい……。
最後の最後で、
root 'static_pages#home'
であるところを、
get 'static_pages#home'
のままにしている。
ようし、やり直そう。
route.rbを修正。
bundle exec rake test よし成功。
(そもそも、これをgit push herokuする前に実行しておけば気付いた話。
チュートリアルにも、ちゃんと「デプロイする前にテストを走らせていますが、こういった習慣を身につけておくと開発に役立ちます」と書いてある)
もう一度、「git push heroku」を実行。
……あれ、herokuの内容変わってない。
相変わらず、controllerの指定がおかしいというエラーのまま。
もしかして、いったんcommitの取り消しをしなければいけないのか。
error: Your local changes to the following files would be overwritten by merge: config/routes.rb Please, commit your changes or stash them before you can merge. AbortingコミットIDを調べる……長い。
Nitrous.ioのターミナルはコピペができないので(多分)延々とIDを打ち込む。
1回は間違えたものの、2回めに何とか正しいIDを入力できた。
error: Your local changes to the following files would be overwritten by merge: config/routes.rb Please, commit your changes or stash them before you can merge. Aborting
しかし、またエラー。
error: Your local changes to the following files would be overwritten by merge:
config/routes.rb
Please, commit your changes or stash them before you can merge.
Aborting
config/routes.rb
Please, commit your changes or stash them before you can merge.
Aborting
Please commitってことは、commitしてくれってことか。
git commit -m "config/route.rb-change"
On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: modified: config/routes.rb no changes added to commit
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
modified: config/routes.rb
no changes added to commit
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
modified: config/routes.rb
no changes added to commit
no changes addedってことは、もう一回、
$ git add -A
をやればいいのかな。
ということで、もう一回、
git add -A
git commit -m "config/route.rb-change"
を実行
config/route.rb-change
1 file changed, 1 insertion(+), 1 deletion(-)
お、うまくいってるようす。
続けて、
$git push
$git push heroku
無事、herokuに第3章の内容をデプロイすることができました。\(^o^)/
教訓:git push herokuの前にテストをすること。