-
in terminal do
docker-compose up
-
create DB
docker-compose run web rake db:create
-
in browser, go to
localhost:5051
-
to login to docker web's bash terminal:
- do
docker ps
to get list of all containers running - to login to the container with the CONTAINER ID after identifying correctly the container you want to login to, do
docker exec -it <CONTAINER-ID> /bin/bash
- do
-
in rails, convention is preferred over configuration
- model name is singular
- controler is plural
-
in controller, the names of the functions must match the route name
- use
rails routes
to get all enabled route names
- use
-
to run migrations, use:
rails db:migrate
-
db/schema.rb
has the current snapshot of the model's table- i.e. the columns and the types for each column
-
this
schema.rb
definition is the authoritative source for your database schema- if you need to create the application database on another
system, you should be using
db:schema:load
, - not running all the migrations from scratch
- this is a flawed and unsustainable approach
- the more migrations you'll amass, the slower it'll run and the greater likelihood for issues
- if you need to create the application database on another
system, you should be using
rails generate controller posts
rails generate model post title:string body:text
- application-wide styling goes in the file -
app/assets/stylesheets/application.css
rails generate model Comment name:string body:text post:references
rails generate controller Comments
rails generate controller pages
-
add
gem 'devise'
toGemfile
-
run
bundle install
-
then run
rails generate devise:install
- then follow the required instructions showed in the response in the CLI
- on required step is to add the host and port for various environments
-
run
rails g devise:views
if devise views need to be customized
- devise is to be leveraged to manage users in the app
- run
rails generate devise User
to generate user model component files - then run migrations (
rails db:migrate
)
- run
-
Generate ruby app within
web
docker containerdocker-compose run --no-deps web rails new . --force --database=postgresql
-
Then, build the app after rails genrates new app
docker-compose build
-
Then configure DB in
config/database.yml
by linking host todb
, and setting username and password
default: &default
adapter: postgresql
encoding: unicode
host: db
username: postgres
password: password
pool: 5
-
Then run the entire docker composite
docker-compose up
-
Then create DB
docker-compose run web rake db:create