railsプロジェクトを作成する

1. railsプロジェクト用のディレクトリを作成する
$ mkdir rails-project
$ cd rails-project


2. GemFileを作成する
$ bundle init


3. GemFileを編集して、gemのインストールを行う

gem 'rails'のコメントアウトを外す。

$ vi Gemfile
  1 source 'https://rubygems.org'
  2
  3 gem 'rails'

$ bundle install --path vendor/bundle --jobs=4

※vendor/bundleディレクトリにgemをインストールする。

4. railsプロジェクトを作成する
$ bundle exec rails new . --database=mysql --skip-turbolinks --skip-test

※データベースはMySQLを指定。
※turbolinksを使用しない。
※test-unitを使用しない。

→下記、mysql2のインストールでエラーが発生したが、Xcodeをアップデートしたら解消した。

[mysql2のインストールエラー]
An error occurred while installing mysql2 (0.4.5), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.4.5'` succeeds before bundling.
         run  bundle exec spring binstub --all
Could not find gem 'mysql2 (< 0.5, >= 0.3.18)' in any of the gem sources listed in your Gemfile or available on this machine.
[エラー解消方法]
$ xcode-select --install
$ gem install mysql2 -v '0.4.5'

※参考にした記事:
qiita.com

5. 必要なgemをインストールする
$ vi Gemfile
$ bundle

※良さそうなgemを探す参考記事:
qiita.com

6. .gitignoreに'/vendor/bundle'を追記する
$ vi .gitignore
 /vendor/bundle


6. railsサーバーを立ち上げて、アクセスしてみる
$ rails s

http://localhost:3000/に初回アクセスすると下記のエラーが発生するので、DBを作成する。
 ActiveRecord::NoDatabaseError (Unknown database 'rails-project_development'):

$ rake db:create


6. railsサーバーを立ち上げて、アクセスしてみる

http://localhost:3000/にアクセスできればOK!!