Skip to content

Instantly share code, notes, and snippets.

@kosukeobata
Last active April 8, 2017 07:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kosukeobata/1a1aea14fdd113d1e91e4b2eb47fa115 to your computer and use it in GitHub Desktop.
Save kosukeobata/1a1aea14fdd113d1e91e4b2eb47fa115 to your computer and use it in GitHub Desktop.
【プログラミング初心者向け】Railsを使って90分で0からアプリを作ってみるハンズオン の当日資料です。

環境構築

コマンドラインツールのインストール

xcode-select --install

brew

  • brewをインストールする
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • brewがインストールされているかを確認
brew -v

rbenv

  • brewのupdate
brew update
  • rbenvのインストール
brew install rbenv ruby-build
  • 設定
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
echo 'export PATH="$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile
  • 再読込
source ~/.bash_profile
  • インストールの確認
rbenv -v

Ruby

  • Rubyがインストールされているかを確認(大体、入っているはずなので)
ruby -v
  • 入ってなかったらインストール
rbenv install 2.3.1
  • デフォルトのRubyを設定
rbenv global 2.3.1

Rails

  • Railsのインストール
gem install rails --no-document
  • Railsがインストールされているかを確認
rails -v

Git

  • Gitをインストール
brew install git
  • Gitがインストールされたかを確認
git version
git config --global user.name "Your Account"
git config --global user.email "Your Email"
  • Gitの設定ができたかを確認
git config -l

以下のようになっていればok

user.name=kosukeobata
user.email=kosuke.obata@bizreach.co.jp

テキストエディタ

[sublimeText](https://download.sublimetext.com/Sublime Text Build 3124.dmg)

Atom


アプリを作ってみよう

Rails Projectを作成

  • ホームディレクトリに移動
cd
  • handson用のディレクトリを作成
mkdir -p rails/workspace
  • handson用のディレクトリに移動
cd rails/workspace
  • railsプロジェクトの作成
rails new biz_handson
  • プロジェクトに移動
cd biz_handson
  • サーバーを起動してみる。
rails server
rails generate scaffold introduction name:string description:text
  • DBのmigrationを行う
rake db:migrate

GitHubにCommit

  • rdocをmdに変更(GitHubがmdのみにしか対応していない為)
mv README.rdoc README.md
  • プロジェクトにgitを追加(.gitなどが生成される)
git init
  • 新規ファイルを追加するコマンド
git add .
  • gitの状態を確認
git status
  • コミット
git commit -am "Initial Commit"
  • gitの状態を確認(ファイル名がなくなっていればok)
git status
  • GitHub画面で新規リポジトリを作成
    リポジトリの名前はbiz_hansonで。
    https://github.com/new

  • remoteとの紐付け

git remote add origin git@github.com:kosukeobata/biz_hanson.git
  • GitHubにアップロードする
git push -u origin master

Herokuにデプロイ

heroku version
  • Herokuにログイン
heroku login
  • 認証鍵を生成
heroku keys:add
  • Heroku用にDBを変更
    変更するファイル: Gemfile
    biz_handsonの中にあります。
    rails4の以外の方はrails12_factorは不要です。
gem 'sqlite3'

group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
  gem 'rails_12factor' -- Rails4の場合
end
  • ルートを変更
    対象ファイル: routes.rb
    biz_handsonのファイルの中のconfigファイルの中にあります。
    下記のように変更
resources :introductions

resources :introductions
root to: redirect('/introductions')
  • 本番環境の変更を適用
bundle install --without production
  • Herokuを作成
heroku create
git commit -am "Create Heroku."
git push origin master
git push heroku master
  • HerokuのDBのmigration
heroku run rake db:migrate
  • アプリを開く
heroku open

早く終わって手持ち無沙汰な方向け

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment