Ruby on Rails Log Levels: Examples and Best Practices

Logging is important in any software development project because it helps to understand how the application is behaving and identify issues when they occur. The errors of an application cannot all be treated in the same way, as they have different levels of importance. Depending on where the error occurs in your application, it can be fatal to a process or just a warning.

Rails default Dockerfile

Docker has become an industry standard. It allows developers to create, deploy, and run applications inside containers. In Rails 7.1, Dockerfiles are included by default. This makes it easier than ever to deploy Rails applications using Docker.

Showing All Headers in Action Mailer Previews

ActionMailer previews can now display all email headers. This allows developers to check all headers, when testing locally.

Using Signed Global IDs with Polymorphic Select Fields in Rails Forms

Polymorphic associations allow a single association to reference multiple models. In a polymorphic association, the association name is used to store the name of the associated model, and the _id and _type attributes are used to store the ID and type of the associated record. However, polymorphic associations can be challenging to work with when it comes to using select fields, especially when there are multiple types of associated models.

Using Date Ranges in Rails Queries

When working with dates in Rails, it’s common to want to find records that fall within a certain range of dates. For example, you might want to find all orders placed between two dates, or all events scheduled for a certain week.

Turbo Streams Duplicate Element When Appending/Prepending

In January, 2021 a bug was reported in Turbo that caused duplicate DOM elements. In this post we’ll explain the bug and how it was fixed.

ActiveRecord regroup method

ActiveRecord’s regroup method is a shorthand for using unscope to remove existing groups.

Rails counter available in collection partials

Rails makes a counter variable available within partials that are rendered with a collection. This variable follows the name of the collection. A @users collection has a counter called user_counter. The counter works like the index on an each loop. It counts the number of times a partial has been rendered. Let’s look at an example.

Exploring the syntax_suggest feature in Ruby 3.2

Ruby 3.2 introduces the new feature syntax_suggest, formerly known as the gem dead_end, now integrated into Ruby. Catch and fix syntax errors are now more robust helping you to find the position of errors such as missing extra parentheses, commas, superfluous ends, errors such as missing or extra curly braces related to string interpolation, and semicolons.

Deploying Rails with Render

Heroku recieved some negative press for the removal of it’s free tier. Render is a cheaper alternative that boasts many benefits over Heroku. We believe Heroku is still the quickest way to spin up a Rails app but Render is close behind and less than half the price.

How to use Enumerator::Product in Ruby 3.2

Ruby 3.2 brings a convenient new addition that enables combining elements from various arrays or enumerable objects with ease. Enumerator::Product, one of the most convenient new methods, can be especially useful when working with large data sets or when generating combinations for testing purposes.

Writing to DynamoDB via Rails models

ActiveRecord is a core part of Rails, an ORM layer that sits on top of relational databases like Postgres or MySQL. However, it doesn’t natively support DynamoDB. Recently, we worked on a project to migrate part of a Rails app to Lambda functions. We began the migration by adding logic for writing to DynamoDB. Here’s how we did it.

How to Use the flat_map Method in Ruby

As a Ruby developer, you have probably used the map method to transform arrays and other collections of data. But have you ever needed to transform an array and flatten the result in one go? This is where the flat_map method comes in.

Using transform_values to Transform Hash Values in Ruby

In Ruby 2.4, a new method called transform_values was introduced to help transform hash values using a block. This method can be particularly useful when you need to modify the values in a hash without changing the keys.

Using compact_blank to Filter Form Parameters in Rails

In Rails 6.1, a new method called compact_blank was introduced to help filter out nil and blank elements from an array. This method can be particularly useful when working with form parameters, where some fields may be left blank or undefined.

Building webhook endpoints with Rails

Building a Rails controller is simple and well documented. Follow the ‘Rails way’ and your life is easy. However, webhook endpoints require a different approach. In this post you’ll learn how to build maintainable and secure webhook endpoints.

Sending Slack messages from Rails

This tutorial explains how to send Slack messages from a Rails application.

List S3 contents and download links in Rails

This post explains how to iterate over the contents of an AWS S3 bucket and generate download links for each object. This example uses aws-sdk version 2. At the time of writing, version 3 is the latest but there’s still a lot of legacy apps that use v2.

Deploying a legacy Rails app to Heroku, via Docker

Recently, we worked on deploying a legacy Rails app to Heroku. The minimum Ruby version that Heroku supports is 2.7.6. Apps running older versions must be upgraded before they can be deployed. Thankfully, this problem can be solved by deploying the app as a container. This post explains how to containerize an application and deploy it to Heroku.

Building a dynamic dashboard with Hotwire, part 2

In part 1 we built an admin panel and used Turbo Streams to make revenue dynamic. In this post we’ll continue building out the admin panel. We’ll implement tabs, using Turbo Frames, then finish up by making ‘real time orders’ dynamic.

Building a dynamic dashboard with Hotwire, part 1

In this series we are building an admin panel, using Hotwire. The admin panel will have multiple tabs and plenty of interactivity. Let’s get started.

Hotwire turbo_stream_from single update bug

Recently, we encountered a bug with some Stimulus code. We were trying to stream updates for a small partial and found that data only refreshed on the first update.

Features and Benefits of Dedicated Software Development Team Model

A dedicated software development team is a collaborating model in which a client engages an outsourced team of project managers, software developers, QA testers, and other specialists offered by the software development vendor.

Designing a regex test feature with Stimulus pt 2

In part 1 we built a Stimulus controller that tests a regex, however, there is a problem with that solution. Ruby and JavaScript regex implementations are slightly different. In our case, we want users to verify their regex using Ruby’s regex implementation. To do that, we need to evaluate the regex on the server side.