PostgreSQL
myapp という rails プロジェクトを作成する前提で、データベース名は myapp_development
としておきます。(開発環境のデフォルトが {project}_development のため)
zsh
$ brew install postgresql
# 起動
$ postgres -D /usr/local/var/postgres
# 上のコマンドはログを出しているので、別コンソールで。作成。
$ createdb myapp_development
Ref. ローカル Mac で PostgreSQL を起動したり停止したり
Rails 5.1.0.beta1
zsh
$ mkdir workspace; cd $_
$ bundle init
$ vi Gemfile
Gemfile
source "https://rubygems.org"
gem "rails", "5.1.0.beta1"
zsh
$ bundle install --path vendor/bundle
$ bundle exec rails new -BT -d=postgresql myapp
$ cd myapp
$ bundle install --path vendor/bundle
$ bundle exec rails s
ここまでで、localhost:3000
にアクセスが可能。
scaffold
zsh
$ bundle exec rails g User name:string email:string
$ bundle exec rails db:migrate
$ bundle exec rails s
4系までは、rake db:migrate
だった。
フィアル構成について
上のサンプルだとこのようなファイル構成になります。
└── workspace
├── Gemfile
├── Gemfile.lock
├── myapp
│ ├── Gemfile
│ ├── README.md
│ ├── Rakefile
│ ├── app
│ ├── bin
│ ├── config
│ ├── config.ru
│ ├── db
│ ├── lib
│ ├── log
│ ├── package.json
│ ├── public
│ ├── tmp
│ └── vendor
└── vendor
└── bundle
いつも、上のような構成でやっていたのですが、これは、Gemfile が2つできます。これでもいいとは思うのですが。もし下のような構成にしたい場合。
└── workspace
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
├── bin
├── config
├── config.ru
├── db
├── lib
├── log
├── package.json
├── public
├── tmp
└── vendor
Gemfileを上書き
$ bundle exec rails new . -BT -d=postgresql --force
とすればよいとおもいます。
以上です。