Lewis Youl

Counting associated records with PostgreSQL and Rails

There are many times when debugging or reporting that you may need to count the number of records that a certain record may have associated with it. PostgreSQL provides you with the tools to do this efficiently

29 Jul 2022-
PostgreSQL Ruby on Rails

Set a Statement Timeout for PostgreSQL Queries in Rails

Long running queries can tie up database connections, eventually bogging down your app and causing it to come to a grinding halt. Thankfully you can leverage statement_timeout to cause long running queries to raise an error.

29 Jun 2022-
PostgreSQL Ruby on Rails

Quick Reference - PostgreSQL Joins

I use joins regularly in my day to day work both explicitly and implicitly. However I regularly forget which type of join does what so I've created this post to serve as a quick reference guide.

20 Jun 2022-
PostgreSQL

Breaking out of Turbo Frames

When you navigate using an anchor element inside a Turbo Frame the default behaviour is for Turbo to handle this and replace only the containing Turbo Frame from the matching one in the response. This post summarises how you can change the default behaviour to conditionally replace Turbo Frames.

09 Jan 2022-
Hotwire Ruby Ruby on Rails Turbo

Testing the versions table with PaperTrail and RSpec

The PaperTrail gem provides version tracking for your ActiveRecord models but the creation of version entries is skipped in the test environment. This post investigates how to turn on and test versioning for specific tests.

26 Oct 2021-
RSpec Ruby on Rails

Programmatic Form Submissions with Turbo Streams

I recently encountered a quirk with programmatic form submissions and turbo streams whereby using the form.submit() function in a stimulus controller wouldn't cause Turbo to hook into the response. This is a short post on how I solved this issue.

29 Sep 2021-
Hotwire Ruby on Rails Stimulus Turbo

Creating associations on your Rails models prevents N+1 queries

It's fairly common when working on existing or legacy codebases to find models that have instance methods defined on them that return ActiveRecord::Relation collections. This post explains how this can be avoided to improve the performance of your application.

31 Aug 2021-
Ruby Ruby on Rails

Counting with ActiveRecord - Count, Size & Length

Choosing the correct method for counting collections in Rails can be confusing. In this post we weigh up the different options ActiveRecord offers us and pick the best tool for the job.

01 May 2021-
Ruby Ruby on Rails PostgreSQL

Infinitely Scrolling Lists with Hotwire and Zero JavaScript

Hotwire is the New Magic from the folks over at Basecamp. It allows you to build dynamic modern web applications without needing to write much/any javascript by utilising server rendered HTML. Here we use Hotwire to create an infinitely scrolling list.

18 Apr 2021-
Ruby Ruby on Rails Hotwire

Automate your RSpec test suite with Guard

RSpec is a wonderful tool for testing regular ruby and ruby on rails applications. However as an application and its test suite grows larger it can become cumbersome to run an entire suite or even an enire file when you make a change. Even switching between your editor and terminal to execute your tests can become tiresome if you are regularly running your specs or practicing Test Driven Development. Guard allows you to automate this process.

09 Apr 2021-
RSpec Ruby Ruby on Rails