Lチカ開発ブログ

https://l-chika.com/の開発ブログ

Railsアプリケーション構築のはじめ

Railsでアプリケーションを構築する最初の手順。

前提

開発環境の前提はこちらに記述。

l-chika.hatenablog.com

環境

手順

Rails初期化

$ mkdir {APPLICATION_DIR} && cd $_
$ bundle init
$ vim Gemfile
source "https://rubygems.org"

gem 'rails', '~> 5.0', '>= 5.0.1'

アプリケーション作成

Gemfileがコンフリクトするので上書きをする。

$ bundle exec rails new . -T -d mysql --skip-bundle --skip-turbolinks
Overwrite {APPLICATION_DIR}/Gemfile? (enter "h" for help) [Ynaqdh] Y

Gemfileの therubyracer をコメントインして、bundle install

 $ vim Gem file
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
$ bundle install --path=vendor/bundle --jobs=4

DB設定

  • ※ 必要に応じて、 config/database.yml を修正
$ ./bin/rails db:create

MySQL確認

$ mysql -uroot
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
| xxxxxxx_development |
| xxxxxxx_test        |
| mysql               |
| performance_schema  |
+---------------------+
5 rows in set (0.00 sec)

起動確認

$ ./bin/rails s -b 0.0.0.0

http://0.0.0.0:3000 にアクセスしてブラウザで確認。

↓が表示されればOK。

f:id:l-chika:20170123193922p:plain

ソース管理する場合は

gitignore

/vendor/bundle/ を追記。

$ vim .gitignore
...
/vendor/bundle/

関連書籍

Ruby on Rails 5 超入門

Ruby on Rails 5 超入門

参考ページ

railsコマンド(rails) - - Railsドキュメント

qiita.com

kz-engineer-scrap.hatenablog.com