Rafał Jaroszewicz

Category: Code

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 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