LoginSignup
2
2

More than 5 years have passed since last update.

Railsプロジェクトを最速Herokuデプロイ

Last updated at Posted at 2015-01-24

前提条件

  • ローカルでRailsプロジェクトが生成できる
  • herokuアカウント作成済
  • heroku toolbeltインストール済

Rails

$ rails new {project name}

Herokuはsqliteは使用できない等、制約がある。

なのでGemfileを調整:

Gemfile
source 'https://rubygems.org'
ruby '2.0.0'    # rubyバージョンを指定


# 7行目くらいにあるsqliteの指定をコメントアウト:
# gem 'sqlite3'


# 末尾に以下追加:

#####################
# add gems
#####################

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
  gem 'therubyracer-heroku'
  gem 'thin'
end

group :production, :staging do
  gem 'rails_12factor'
end

注意:
ローカルrubyバージョンとGemfileに記載したrubyバージョンは合わせる必要がある。
(合っていない場合の対処については別途記事を書く予定 書きました:rbenvでローカル及びHerokuのRubyバージョンを合わせたい

問題がなければ再インストール:

$ cd {project path}
$ bundle install

Git

$ git init

Heroku

ログインしてなければする:

$ heroku login

Heroku側にアプリの場所作る:

$ heroku create

create直後はランダムなアプリ名を付与されるので、
HerokuのDashboardへ行き、任意のアプリ名に変更する。

アプリ名を変更した時点で、gitのリモートリポジトリパスも変更する必要がある(参考:Updating Git remotes - Renaming Apps from the CLI | Heroku Dev Center

なので:

$ git remote rm heroku
$ heroku git:remote -a {変更したアプリ名}

更にプロジェクト直下にProcfile用意、以下を記述:

Procfile
web: bundle exec rails server thin -p $PORT -e $RACK_ENV

色々揃ったのでHerokuへpush:

$ git add -A
$ git commit -m "first commit"
$ git push heroku master

ページが無事開ければOK:

$ heroku open
2
2
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
2
2