LoginSignup
12
9

More than 5 years have passed since last update.

herokuにデプロイするメモ

Last updated at Posted at 2017-03-25

事前準備(済んでいれば飛ばす)

  • 環境
    • vagrant
    • Ubuntu

herokuに登録

https://signup.heroku.com/
上記リンクからまずは登録
(ここで言語設定をRubyにする)

アプリケーションの作成

rails new heroku_sample

cd heroku_sample

rails generate controller home top

rootの変更

config/routes.rb
get 'home#top'

   ⬇︎

config/routes.rb
root 'home#top'

公開手順

環境設定

DBの設定変更

デフォルトはおそらく'sqlite3'でherokuでは、'pg'を使用するため変更が必要

変更前

gem 'sqlite3'

変更後

gem 'sqlite3', group: :development
gem 'pg', group: :production
gem 'rails_12factor', group: :production

本番環境でのdatabaseの設定を変更

ymlファイルのproduction部分を以下に変更

config/database.yml
production:
 <<: *default
 adapter: postgresql
 encoding: unicode
 pool: 5

のちにheroku run rake db:migrateでエラーが出るので回避するため以下の変更を加える
(bin/bundle)
変更前

#!/usr/bin/env ruby2.3

変更後

#!/usr/bin/env ruby

heroku側でAppを作成する

heroku コマンドを有効にする

wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

ここでheroku loginしていなかったらする

heroku create (herokuでのアプリケーション名) --buildpack heroku/ruby

重複できないのでユニークな名前を設定する
buildpack でrubyを指定

デプロイする

git init
git add .
git commit -m "first commit"

git push heroku master

データベースの作成

heroku run rake db:migrate

URL等の確認

heroku info

アクセスしてエラーが出たら. . .

heroku logs

heroku run rails c

上記どちらかで出るエラーを解決する

12
9
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
12
9