3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RailsアプリをHerokuでデプロイする際の注意点

Last updated at Posted at 2019-05-06

はじめに

初投稿です。本とネット教材で半年学んだ程度のヒヨッコです。 AWS cloud9でRuby on Railsプロジェクトを作成し、GitHub経由でHerokuでデプロイしました。 その際に発生したエラー・注意点を備忘録として投稿させていただきます。

Herokuの注意点

Herokuではsqlite3が使えないようなので、本番環境用のgemを別に設定する必要があります。 以下リンクを参考にPostgreSQLを入れました。 (参考)HerokuではSQLite3が使えない?! https://qiita.com/MosamosaPoodle/items/7149aa66f1c087472777

・Rails Gemfileを修正

Gemfile
gem 'sqlite3' 

↓変更する

Gemfile
gem 'sqlite3', groups: %w(test development), require: false
gem 'pg', groups: %w(production), require: false

・Rails Gemfile.lockを削除しbundle installし直す

```rails:Terminal $ rm Gemfile.lock $ bundle install ``` これでRails上の設定は完了です。

AWS cloud9からgit push時の注意点

安全性の観点から、GitHubを二段階認証で管理すべきなのですが、 そうするとcloud9からpushする際にGitHubアカウントパスワードを入力してもエラーになります。
Terminal
Username for 'https://github.com': hoge-user
Password for 'https://hoge-user@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/hoge-user/github-repository-name.git/'

対策として
・GitHubでPersonal Access tokensを発行し、tokenをPassword欄に入力する(https接続)
・SSH接続するよう設定を変更する
の2つがありますが、今回は前者を選びました。
(参考)GitHub「Personal access tokens」の設定方法 https://qiita.com/kz800/items/497ec70bff3e555dacd0

ちなみに個人的にハマった罠が2つありますのでそちらも書いておきます。

  1. Terminal上のPassword入力時は、画面は反応しないが文字はちゃんと入力されている。心配せずに入力する!
  2. コピーした文字をTerminal上にペーストするときはcommand+v (Ctrl+v)で入力しない。右クリック→Pasteでペーストする。

成果

半年間HTML, CSS, JavaScript, Ruby, Rails, AWS cloud9などと悪戦苦闘しましたが、素人でもHerokuでデプロイできました。 飲み会のお会計をシチュエーション別で傾斜計算する簡単なツールです。 Warikan - https://warikanappbygmnori.herokuapp.com/

デザインや計算方法の拙さは本人が一番実感しています。次はもっと良いものを作れるよう頑張ります。

参考リンク

HerokuではSQLite3が使えない?! https://qiita.com/MosamosaPoodle/items/7149aa66f1c087472777 GitHub「Personal access tokens」の設定方法 https://qiita.com/kz800/items/497ec70bff3e555dacd0
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?