Rafał Jaroszewicz

Create dynamic dependant dropdowns with Turbo and Stimulus in Rails 7

Remember my blog post about dynamic dropdowns in rails 6? Outdated. Now we can do it with Turbo frames and it’s so much fun! Turbo Frames allows you to easily create interactive, partial page updates in your Rails app, while Stimulus provides a simple and lightweight way to add interactivity to your HTML. When I’m […]

Specifying a polymorphic has_many through: association in Rails

In my recent project that I’m working on I faced this problem where I have a Client model and two different models for properties, Sale and Rental. To avoid having multiple tables for ClientSales and ClientRentals I wanted to just have ClientProperties, and for that I need a polymorphic has_many through: In Ruby on Rails, […]

Rails + Stimulus.js sorting filter on select

In my new project I wanted to introduce sorting on the index page for my records and I came up with this simple Stimulus.js solution. First, I created the select Then once i have my element in place I can create a Stimulus controller And also attach it to my select Now, let’s attach the […]

Using inline SVGs with Rails attachments

So I was looking for a method to serve attachments uploaded by users in the Rails Active Storage. Regardless of where these are served from, I needed a way to insert them into the document. I read This article by Salazar explaining how to serve SVG icon packs and I realized that with a small […]

Creating model for “related” posts

I wanted to create a section on my page that leads to related posts. One proposition was to create additional table and store from and to ID’s of related posts.   First we want to have our model, nothing special about it, just an example Post class. Next, we need a class that will connect […]

Create honeypot against spam bots in Rails

I was trying to implement something that is less annoying than google recaptcha. Everyone knows that it’s quite exhausting for some users. Also I would like to reduce the amount of requests made to google with all gtags, analytics, ads etc. are already slowing the whole internet down. I found this very old article on […]

Using attr_accessor to clean up your calls between models

In my glorious real estate management app I thought that it’d be cool to know how much rent a tenant has to pay without typing tenant.flat.rent every single time (tenant belongs_to :flat) So instead, we can just use attr_accessor :rent as below. Now I can always access tenant’s rent by simply going for tenant.rent

Create dynamic dependant dropdowns with Javascript in Rails 6.1.4

I managed to pull this stunt off in an app I’m working on. Let’s say we want to have a payment module. On top of the form we have three dropdowns. To make things easier for the user, I want these dropdowns to be dependant, so first I choose the building, then another dropdown only […]

Back to top