Qiita Conference 2025

伊藤淳一 (@jnchito)

なぜあなたの記事には「いいね」が付かないのか?〜あるいは「いいね」よりも大事な技術記事の価値について〜

1
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でアプリを作り始める際のメモ

Posted at

各種インストール済み
自分用のメモ

準備

アプリ作ります

$ rails new myFormApp

ちゃんと作られたか確認します
サーバを起動して http://localhost:3000 を開きます

$ cd myFormApp
$ rails server
スクリーンショット 2019-09-25 14.36.13.png # Git gitで管理します
$ git init
$ git add -A
$ git commit -m "Initialize repository"

Github

githubにアクセス、ログインしてNew RepositoryでmyFormAppリポジトリを作成します
スクリーンショット 2019-09-25 16.18.40.png
GithubをリポジトリのoriginとしてGitの設定ファイルに追加して
ローカルのリポジトリをoriginのリモートにプッシュします

$ git remote add origin git@github.com:snaruse0608/myFormApp.git
$ git push -u origin master

画面が変わってるのを確認します
スクリーンショット 2019-09-25 16.33.22.png

heroku

herokuにあげるためにGemfileを修正します
使っているデータベースがローカルとherokuで異なるので、その設定をします。

gem 'sqlite3' はローカルであるdevelopment環境とtest環境で使用して、
production環境(=本番環境)では使用しないようにします。

Gemfile
group :development, :test do
  gem 'sqlite3' # ここに移動
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

heroku上のproduction環境ではPostgreSQLデータベースを使うようにします

Gemfile
# 追加
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を表示してみます。
コントローラとルーティング設定を修正します。

/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  def hello
    render html: "hello, world!"
  end
end
/config/routes.rb
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

herokuからOpen appを押下します
スクリーンショット 2019-09-25 17.26.42.png

終わり

次から編集する時に毎回やることまとめ

たぶん

編集前

$ 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
1
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
1
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?