LoginSignup
0
0

More than 5 years have passed since last update.

HerokuでRuby on Railsを動かすときに躓いたところ

Posted at

スペック

Windows10(PC)
ほぼ素人(本人)

環境構築

当初はRubyのインストール -> gem install rails の順で進めていたが、
rails server を打つと、謎のLoadErrorが起きて詰む。
mingw32関連のエラーっぽいのだが丸一日調べても解決できず…。
あきらめかけたその時に、Railsまで含めたインストーラーがあることを知る。
http://installrails.com

こちらで試したところ5分で環境構築が完了する。
あの苦労は何だったのか…。

Herokuへのコミット

2箇所修正が必要

Gemfile

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

↓HerokuはPostgreSQLで動いているので、本番(production)では、その対応が必要

# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
gem 'sqlite3', group: [:development, :test]
gem 'pg', group: :production

config/database.yml

* 事前にHeroku上で、PostgreSQLのアドオン(Heroku Postgres)を有効にしておく。

production:
 <<: *default
 database: db/production.sqlite3

↓以下のように設定する

production: 
# <<: *default
# database: db/production.sqlite3
  encoding: unicode
  adapter: postgresql
  username: username
  port: 5432
  host: hostname
  database: database
  password: password

username, hostname, port, database, passwordは、
Heroku configコマンドをたたくとDATABASE URLがわかるので、そこから判別する

postgres://username:password@hostname:port/database

以上でOKでした :)

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