3
0

More than 1 year has passed since last update.

初めてのRailsチュートリアルに挑戦!第1章

Last updated at Posted at 2022-07-02

学習内容

1.環境構築

  1. AWS Cloud9でユーザ登録、クラウドIDE作成
  2. Railsをインストール
     *バージョン6.0.4を利用。Rails6(第6版)の電子書籍に合わせた。

2.最初のアプリケーション

  1. Railsのアプリケーション作成
  2. hello_appの作成
     *第1章で使うアプリ。第2章以降は別のアプリを使う
  3. Bundlerインストール
  4. webpackerインストール
  5. rails server起動
     *開発マシンでのみブラウズできるローカルWebサーバー
  6. MVCの理解
  7. 「hello, world!」の表示

3.Gitによるバージョン管理

  1. Gitインストールとセットアップ
  2. Git初期化
  3. Git追加とコミット
  4. Gitブランチ作成、編集、マージ
  5. Gitプッシュ

4.Herokuのセットアップとデプロイ

  1. 本番環境用以外のgemをインストール
  2. Herokuインストール

学習時のエラー対応

1.Bundlerインストール時のエラー

bundle _2.2.17_ installを実行した際、Gemfileで定義したバージョンより、最新のバージョンが存在するため、アップデートを促される。

 $ bundle _2.2.17_ install
Fetching gem metadata from https://rubygems.org/...........
You have requested:
  listen = 3.1.5

The bundle currently has listen locked at 3.7.1.
Try running `bundle update listen`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

そのため、bundle update listenを実行すると、

 $ bundle update listen
Fetching gem metadata from https://rubygems.org/...........
You have requested:
  spring = 2.1.0

The bundle currently has spring locked at 2.1.1.
Try running `bundle update spring`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

すると今度は、springもアップデートを促されるので、 bundle updateで全てのgemを一気にアップデートして解決。

2.webpackerインストール時のエラー

rails webpacker:installを実行した際に、conflict(競合)が発生。

$ rails webpacker:install
warning ../../package.json: No license field                             
    conflict  config/webpacker.yml
Overwrite /home/ubuntu/environment/hello_app/config/webpacker.yml? (enter "h" for help) [Ynaqdhm] 

ただ、既にあるwebpackerをOverwrite(上書き)するか、聞かれているだけなので、Enter。
他にも「webpacker.yml」、「bin/webpack」、「bin/webpack-dev-server」をOverwriteして解決。

3.GitHubにプッシュする際の認証

初めてgit push -u origin masterを実行すると、以下の認証が必要となる。

$ git push -u origin master
Username for 'https://github.com/'ユーザネーム'/hello_app.git': 'ユーザネーム'
Password for 'https://'ユーザネーム'@github.com/'ユーザネーム'/hello_app.git': 

パスワードはログイン時のものではなく、個人トークンでログインして解決。

4.Herokuにプッシュする際のエラー

git push heroku masterを実行した際に、エラー発生。

$ git push heroku master

fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

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

調べてみると、gitがリモートのリポジトリを参照出来ていなかったため、以下のように追加。

$ git remote add heroku https://git.heroku.com/アプリケーション名.git

その後、git push heroku masterでpushができたので、解決。

学習を終えて

エラーが発生した際は、落ち着いてエラー内容を確認して対処することの大切さを学んだ。
また、バージョンのわずかな違いによってもエラー発生するので、テキストと全く同じバージョンになるように心がけた。
そして、コマンドを入力するだけでは、ただの写経なので意味をしっかり理解しながら進めることに意義があると実感した。

3
0
0

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