仁瓶悠斗の裏表紙

白紙の自分を七色に染めていく知識を書く裏表紙です

【Rails】Rails tutorial始めました&つまづいたまとめ

よくよくWeb系の勉強どこから始めようか手をつけあぐねていました。 Heroku使ってWebアプリケーションをDeployするところまでをやった事が無かったので、 Tutorialの登竜門とよく聞くRails tutorialから始める事にしました。

railstutorial.jp

やった事、環境

  • 今回はRails 5.1(第4版)を参考にしています。

  • Cloud9を利用せずにMacを利用しています。

  • 今回は第1章、HerokuへのDeployまでをしました。

  • 途中にある.gitignoreについては、GitHubにおいてあるRailsの.gitignoreをコピペしました。

https://github.com/github/gitignore/blob/master/Rails.gitignore

結果

1.5.4で適当なURLに変更できるようだったので変更をし、無事HerokuへのDeployまで出来ました。

https://yutori-hello-app.herokuapp.com

ちょいこけ

今回Rails自体でつまずいてはおらず、環境まわり(特にGit)の設定がうまくいかずにトラブルシューティングをしていました。 流れとしては Git pushしようとした →アドレスが間違ってるのをhello_app/.git/configの中身を修正 →ヒモ付ができてないのをgit branch --set-upstream-to=origin/master masterで紐づけ →ファイルが被ってるのをgit pull --allow-unrelated-historiesでpullした後にコンフリクト解消 DONE!!

ちょいこけ① remote add するアドレスを間違っていた

最初にremoteのリポジトリを設定し、git push -u origin --allをしようとしたところ、

ssh: Could not resolve hostname bitbucket: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

どうもリポジトリがないと言われてる?

git config --list で確認。すると

hello_app yutonihei$ git config --listcredential.helper=osxkeychain
user.name=Yuto Nihei
user.email=***
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=git@bitbucket.org:yutonihei/hello_app.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

Gitのリモートリポジトリの場所の指定を失敗していました。。 remote.origin.url=git@bitbucket:yutonihei/hello_app.gitremote.origin.url=git@bitbucket.org:yutonihei/hello_app.git ですね。

ちょいこけ②紐付けができてない?

remoteリポジトリの設定を終わったタイミングでちょいこけ③の状態に気づき、git pullをしました。

hello_app yutonihei$ git pull
warning: no common commits
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From bitbucket.org:yutonihei/hello_app
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

と出ました。どうもremoteのブランチとlocalのブランチの紐づけがうまくいっていない?

git branch --set-upstream-to=origin/master master

でブランチの修正ができました。

ちょいこけ③ README.mdの重複の修正

原因としては、rails _5.1.6_ new hello_appを実行して生成された README.md ファイルと、 Bitbucket上でリポジトリを作成した際に生成された同ファイルがコンフリクトしていたためでした。

修正する方法として、git pull --allow-unrelated-historiesでファイルを強制的にpullし、その後にコンフリクトしている原因を解消しました。

qiita.com

また、初めてコンフリクトした画面をVisual Studio Code上でみました。。

f:id:yutonihei:20181013174034p:plain

最後に

とりあえずDeployまで出来て一安心。ただ1章進めるのに3時間+α以上かかってしまったので、 当然の事ながら次はその点注意しながら作業を進めていきたいです。 2章からが具体的なRails開発になっているようなので、引き続き頑張っていきたいです。

また、今回はもくもく会で作業をしていたので、 知り合いの方に教えていただきながら完走する事ができました、ありがとうございます。