Convert Rails views from html.slim to html.erb

orange plastic blocks on white surface

Install Slim as a gem

gem install slim

Create a shell script in your app/views folder

slim2erb.sh

for file in $(find . -name \*.slim); do
  erb_file="${file%.*}.erb"
  slimrb -c --rails --erb $file | sed 's/::Temple::Utils\.escape_html((\(.*\))) %>/\1 %>/g'  > $erb_file
  echo $erb_file
done
find . -name "*.slim" -type f -delete
sh slim2erb.sh

Unfortunately, you will need to do some manual work – slimrb doesn’t generate properly formatted ERB templates.

Dokku – Build your own Heroku and deploy your Rails application

building photography

Dokku is powered by Docker PaaS implementation

Install Dokku on Ubuntu VPS

wget https://raw.githubusercontent.com/dokku/dokku/v0.26.8/bootstrap.sh
DOKKU_TAG=v0.26.8 bash bootstrap.sh

Add SSH key/s

echo 'copy mykey1 pub ssh key here' | dokku ssh-keys:add mykey1
echo 'copy mykey2 pub ssh key here' | dokku ssh-keys:add mykey2

Set Domain for Dokku

dokku domains:set-global example.com

Install Postgre

dokku plugin:install https://github.com/dokku/dokku-postgres.git

Install Redis

dokku plugin:install https://github.com/dokku/dokku-redis.git redis

Deploy Ruby on Rails Application

Run-on your local machine (The example is based on an existing Rails application with Git source version control. You will gonna need a dokku client)

cd myapp/
dokku apps:create myapp

Create and link Postgre database for your application

dokku postgres:create myapp_database
dokku postgres:link myapp_database myapp

Create and link Redis instance for your application

dokku redis:create myapp_redis
dokku redis:link myapp_redis myapp

Deploy on Dokku

git remote add dokku [email protected]:myapp
git push dokku master:master

Run-on the dokku server

dokku run myapp rake db:migrate
dokku run myapp rake db:seed
dokku config:set myapp ENV1=VALUE1 ENV2=VALUE2 # set env variables for your app

Useful commands

Tail logs

dokku logs myapp -t
dokku nginx:access-logs myapp
dokku nginx:error-logs myapp

Run Rails console

dokku run myapp rails c

PostgreSQL console

dokku postgres:connect myapp_database

Print application configs

dokku config myapp

Restart/Re-deploy application

dokku ps:restart myapp
dokku ps:rebuild myapp

Tips

Skip the deployment on container rebuild

dokku config:set myapp DOKKU_SKIP_DEPLOY=true

Change Proxy port for application

dokku proxy:ports-set myapp http:80:3000

Import SQL dump

dokku postgres:connect myapp_database < myapp_database.sql

Add persistent storage for file uploads

mkdir -p /var/lib/dokku/data/storage/myapp
dokku storage:mount myapp /var/lib/dokku/data/storage/myapp:/app/storage
chown -R dokku:dokku /var/lib/dokku/data/storage/myapp
dokku ps:restart myapp
dokku storage:report myapp

Rails 7 with Bootstrap + React + TypeScript

Generate new Rails application

rails new myapp -j esbuild -c bootstrap

Add React and TypeSript with npm

cd myapp
npm i react react-dom @types/react @types/react-dom typescript

Init tsconfig.json

npx tsc --init --project tsconfig.json --noEmit --jsx react

Build and Check. Add to packages.json

  "scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds",
    "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules",
    "check-types": "tsc --project tsconfig.json --noEmit --watch --preserveWatchOutput"
  }

Procfile

web: bin/rails server -p 3000
js: yarn build --watch
css: yarn build:css --watch

Elasticsearch – single node cluster with Docker

magnifying glass on white table

This example is only for development purposes!

docker run -d \
  --name=elastic \
  -p 0.0.0.0:9200:9200 \
  -p 0.0.0.0:9300:9300 \
  -e "discovery.type=single-node" \
  --restart=unless-stopped \
  docker.elastic.co/elasticsearch/elasticsearch:7.16.3

Test with cURL request:

curl -X GET 'http://IP:9200'

Should receive:

{
  "name" : "7ca5c260ab24",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "FV27yhVISOiGQboJAmAqDw",
  "version" : {
    "number" : "7.16.3",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "4e6e4eab2297e949ec994e688dad46290d018022",
    "build_date" : "2022-01-06T23:43:02.825887787Z",
    "build_snapshot" : false,
    "lucene_version" : "8.10.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Install Heimdall with Docker

Heimdall is a web based application dashboard

Example installation using Docker

docker run -d \
  --name=heimdall \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Europe/Sofia \
  -p 8080:80 \
  -p 8443:443 \
  -v /home/dock/heimdall/config:/config \
  --restart unless-stopped \
  ghcr.io/linuxserver/heimdall

Nginx Proxy Config for host with SSL:

        location / {
             proxy_http_version 1.1;
             proxy_set_header Host $host;
             proxy_set_header Connection "";
             proxy_pass https://0.0.0.0:8443/;
        }