各種インストール済み
自分用のメモ
準備
アプリ作ります
$ rails new myFormApp
ちゃんと作られたか確認します
サーバを起動して http://localhost:3000 を開きます
$ cd myFormApp
$ rails server

$ git init
$ git add -A
$ git commit -m "Initialize repository"
Github
githubにアクセス、ログインしてNew RepositoryでmyFormAppリポジトリを作成します
GithubをリポジトリのoriginとしてGitの設定ファイルに追加して
ローカルのリポジトリをoriginのリモートにプッシュします
$ git remote add origin git@github.com:snaruse0608/myFormApp.git
$ git push -u origin master
heroku
herokuにあげるためにGemfileを修正します
使っているデータベースがローカルとherokuで異なるので、その設定をします。
gem 'sqlite3' はローカルであるdevelopment環境とtest環境で使用して、
production環境(=本番環境)では使用しないようにします。
group :development, :test do
gem 'sqlite3' # ここに移動
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
heroku上のproduction環境ではPostgreSQLデータベースを使うようにします
# 追加
group :production do
gem 'pg'
end
gemをインストールします
ローカルにはPostgreSQLをインストールしないように注意します
$ bundle install --without production
成功したらコミットします
$ git commit -a -m "Update Gemfile for Heroku"
herokuに新しいアプリケーションを作成します
$ heroku create
作られたらherokuにpush
$ git push heroku master
画面をみてみる
今、Open appを押下するとエラーのページが表示されるので、HelloWorldを表示してみます。
コントローラとルーティング設定を修正します。
class ApplicationController < ActionController::Base
def hello
render html: "hello, world!"
end
end
Rails.application.routes.draw do
root 'application#hello'
end
githubとherokuにpush
$ git add -A
$ git commit -m "hello world"
$ git push
$ git push heroku
終わり
次から編集する時に毎回やることまとめ
たぶん
編集前
$ git checkout -b BranchName
編集後
$ git add -A
$ git commit -m “Commit Message“
$ git checkout master
$ git merge BranchName
$ rails test
$ git push
$ git push heroku