1
0

More than 3 years have passed since last update.

rails tutorial2章進めた時の覚書

Last updated at Posted at 2021-08-27

2章でhello_appに加え、toy_appを製作したが、

$ git push heroku master

は同じように叩いてしまっていいのか?
上書きされる感じになるのかな?

herokuの管理画面見る限り、
- hello_app
- toy_app

の2つがアップロードされているわけではない?から、上書きされてるのかしら。

 $heroku open --app アプリ名

参考: https://qiita.com/RyomaMaeda/items/60c96e8255996cbb375c

$ heroku apps

アプリブラウザで確認したらエラー
image.png

rails tutorialに則りログ確認からの migrate

$ heroku logs
ActionView::Template::Error (PG::UndefinedTable: ERROR:  relation "users" does not exist
$ heroku run rails db:migrate

無事表示を確認
image.png

ユーザー作るとまたさっきのエラー出る

最後に、もし2.3.3.1の演習をやっていれば、「最初のユーザーのマイクロポストを表示する」というコードを削除する必要があることに注意してください。

と書いてあるが、2.3.3.1の演習がどれかわからない
image.png
これだ

その後、該当コードをコメントアウトして、git add するが、ファイルの変更がトラッキングされず、commitもpushもできない

一度cloud9上でrunボタンを押してから再度 git diff したらちゃんと変更がトラッキングされていた。
謎。

ちなみに下記コメントアウトしてpushしたら、ユーザー製作してもエラーでず正常に動作した。

$ <%= @user.microposts.first.content %>

なんで?呟きがないのに呟きを表示しようとしたからエラーがでた?
検証するために、下記コードを書いてユーザーを新規に製作したところ、普通に同じエラーでた。
コードがそもそも間違っているのか、呟きがないのに呟きを表示しようとしたから という仮説が間違っているからのどちらかなのかはわからず。

if @user.microposts.first.content != null then
    <%= @user.microposts.first.content %>
  else
  end

一個前のコメントアウトしただけのcommitに戻す

$git log #戻したいcommitのハッシュ値を取得
$git reset --hard ハッシュ値

この後、

$git push heroku master # エラー出る
$git pull heroku master

とかしてたらわけわかんなくなった。

1
0
1

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
1
0