> vagrant up
Configure for using postgres client in Rails.
$ export POSTGRES_HOST=localhost
$ export POSTGRES_PORT=5432
$ export POSTGRES_USER=postgres
$ export POSTGRES_PASSWORD=password
Copy sample Rails application. (If you donot use sample, remove synced_folder from Vagrantfile.)
$ cp -r /tmp/sample_rails ./
$ cd sample_rails
$ docker-compose up -d
Create new Rails project.
$ rails new web --database=postgresql
$ cd web
Update config for DB connection.
$ vi config/database.yml
default: &default
adapter: postgresql
encoding: unicode
+ host: <%= ENV.fetch('POSTGRES_HOST') %>
+ port: <%= ENV.fetch('POSTGRES_PORT') %>
+ user: <%= ENV.fetch('POSTGRES_USER') %>
+ password: <%= ENV.fetch('POSTGRES_PASSWORD') %>
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
Create DB and install webpacker.
$ rails db:create
$ rails webpacker:install
Scaffold sample feature.
$ rails g scaffold user user_number:string first_name:string last_name:string
$ rails db:migrate
Start Rails server.
$ rails s -p 3000 -b 0.0.0.0
=> localhost:3000/users