Skip to main content

This Week I've Learned - 2024-W49

PERSONAL

No post last weeks - had to take a break. Learning that rest is important, even when there’s lots to do.

TECH & CODING

WordPress Got Humadroid’s landing page rewritten in WordPress to let Bartek edit content without my help. Big thanks to Ilia and Florin from inntech who handled it. The frontend is super fast, but I was surprised how slow the admin side has become - making complex changes is really painful.

Nested forms with just Turbo Streams

Edit 11.12.2024: I’ve updated turbo stream responses to include field index.

Recently I was working on implementing dynamic nested forms using Turbo Streams, focusing on handling both new and persisted records without custom JavaScript. Well, mostly for fun, to try something new. And while there are multiple approaches to this problem, including Stimulus controllers or plain JavaScript, Turbo Streams offer a clean, server-driven solution that leverages Rails conventions.

The Core Concept: Form Manipulation vs Persistence

A key aspect of this implementation that might not be immediately obvious is that the IngredientsController doesn’t actually persist any data. Its sole responsibility is to manipulate the form structure through Turbo Stream responses.

This Week I've Learned - 2024-W44

CODING

  • Found a nice Ruby gem (actually it was recommended to me in this Xitter thread) - procore-oss/blueprinter which seems to be a very nice serializer (JSON Object Presenter) for Ruby. As I was implementing API for Humadroid recently with Time-To-Market in mind, I’ve actually settled on Grape & Grape Entity, but when we’ll be creating v2 of it in bigger team, we’ll most likely look for alternatives and blueprinter looks like a solid contender.

This Week I've Learned - 2024-W42

Trying to restart this blog, one thing at a time. For quite some time I wanted to start publishing some smaller blobs I find interesting, but giving each and everyone a post seemed wasteful. That’s why I’ve decided to publish my weekly learnings and findings - some links, some thoughts from development, some API methods I haven’t used before. Without further ado, here it is for the first time.

This week I’ve learned:

Figuring Out User Invitations in Humadroid

Building Humadroid by myself is tough. I’m good at writing code, but coming up with new ideas for the app can be really hard when I don’t have anyone to talk to about it. Sometimes I write these blog posts just to help me think things through.

The Invitation Problem

The other day, my friend wanted to try out Humadroid. It made me realize something important: when someone signs up, they might not know what to do next. That’s a big problem for an app that’s supposed to help manage people! I spent a lot of time thinking about different ways to get people into Humadroid. Here’s what I came up with:

Multiple apps on one server using kamal

Kamal’s effectiveness is undeniable. Its integration with power-efficient bare-metal servers, such as those available on Hetzner.com, elevates its appeal, allowing for the simultaneous deployment of multiple Rails applications (or applications developed with other frameworks) on a single server. This setup can be further enhanced with the inclusion of additional components like PostgreSQL or Redis.

It’s important to note that while each service in this configuration operates within its own namespace, Traefik does not share this characteristic; only one Traefik service can be included in our setup. In my scenario, I’ve designated the Prograils service, which powers the prograils.com website, as the primary service. Below is the complete configuration for this setup:

Self-hosting tunnel exposing local ports to the internet with custom domain

Although there are some existing solutions to expose local port to the internet, I’ve decided to use self-hosted solution. I’ve prefered this over hosted one for few reasons:

  1. I wanted to have some pre-configured subdomains
  2. I wanted those subdomains to be fixed and/or reserved just for me
  3. Custom domain was a nice addition
  4. Cost of hosted solution was just too high to justify it.
  5. It was just a fun exercise

Idea is simple - anyone accessing address like some_name.yourdomain.dev will actually access your dev environment on specific port, eg. localhost:3000. Overall cost of that will be 5$ for cheapest linode + domain cost.