Railsアプリケーション構築のはじめ
Railsでアプリケーションを構築する最初の手順。
前提
開発環境の前提はこちらに記述。
環境
手順
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。
ソース管理する場合は
gitignore
/vendor/bundle/
を追記。
$ vim .gitignore
... /vendor/bundle/
関連書籍
- 作者: 掌田津耶乃
- 出版社/メーカー: 秀和システム
- 発売日: 2016/12/17
- メディア: 単行本
- この商品を含むブログを見る