We love reading, watching, and listening in order to keep our skills sharp and our perspectives fresh. Here are some of the resources we learned from this month.
🚨 Experimental feature alert! 🚨Ractors were introduced in Ruby 3 and represent an actor-model abstraction. Ractors provide true-blue parallelism and do not have thread-safety concerns. Intrigued? So are we. This article will allow you to get your feet wet with Ractors in Ruby and understand what they are, why they are useful, and how to implement one of your own.
Can’t get enough of the Hotwire ecosystem? Same. The Rails community has really rallied around the suite of tools that includes Turbo, Stimulus, and Strada (yet to be released). Since it came on the scene in 2021, there have been an increasing amount of projects that seek to augment its functionality. See TurboReady, which extends Turbo Streams to allow full control of the browser’s DOM. This will allow you to write code like this:
turbo_stream.invoke "console.log", args: ["Hello World!"]. Pretty neat, huh? Just be sure to pay special attention to “A word of caution” in the README. 😉
A new addition in Rails 7. This method is a nifty shorthand for writing queries that need to order the records in a non-standard way. Now you can simply write
Category.in_order_of(:id, [3, 1, 2]) and Rails will translate it into “CASE… WHEN”, which will make the result match the order passed in the array. One caveat: this method will also limit the records to those that match one of the values passed, in our example categories with other IDs will not be returned, even though upon inspection the raw SQL does include an
else (at least in Postgres). That was done so that the method matches its Enumerable counterpart. I think a version of this method without this constraint would also be a welcome addition.
The dreaded “white screen” scenario. You’ve seen it, I’ve seen it, but the good news is - we don’t have to see it so long as we take care to handle errors and exceptions gracefully. One way to accomplish this in our React apps is to leverage Error Boundaries, which are plain ol’ class React components that implement the
componentDidCatch(error)function. This article will walk you through how to implement Error Boundaries in your app, cover some limitations, and introduce libraries that can help in advanced contexts.
In the age of social media, images with filters applied are a dime a dozen. But have you ever attempted to create your own using The Orton Effect? The Orton Effect is a technique in photography that involves taking an in-focus image and an out-of-focus image and layering them on top of one another to create a “dreamy” visual effect. This article walks you through how to implement this technique using CSS and React.
POST requests? We thought this was a democracy!? Oh well. We still think it’s pretty neat that there is an official API that allows the public to ingest Congressional data. There are a handful of resources available including but not limited to