Team Qameta Ruby on Rails

Identify unused Routes in Ruby on Rails

Custom Rake Task: Identify unused routes in Ruby on Rails

Rails routes map URLs of a Ruby on Rails application to controller actions. As a project grows, many new routes get added and older ones might become obsolete. Cleanup of unused routes is a good practice to keep the codebase clean and maintainable. This article shows how you can identify unused routes in Ruby on Rails before 7.1 and after 7.1 with built-in tooling.

Use Geocoder and MaxMind DB to Geocode IP Addresses

Explore Google IP address data

Utilizing IP addresses for communication is a fundamental aspect of many web applications employing HTTP(S) as their protocol, particularly those interconnected to the internet. However, a multitude of IP addresses are also generated through protocols such as SSH, SMTP, or IMAP. In this article, we’ll explore how to determine their origins and extract valuable data using the geocoder gem in conjunction with the MaxMind GeoLite2 Database.

Default URL Options in Ruby on Rails

Ruby on Rails default_url_options in console

Like most Ruby developers you have to set a default_url_options on a Ruby on Rails project. Depending on the use case you have to set several of them with different values.

The name of the method default_url_options is the same, but it is used in different contexts (controller, mail, or file storage, it may be confusing and can even have side effects for your project you have to figure out yourself. Depending on the value you set, they may be reused in other contexts like ActiveStorage, ActionMailer, and third-party gems like devise. I couldn’t find any official documentation for the most common cases (web, mail, file storage, test), I’ve written one.

Working with Legacy Ruby on Rails: spring.gem fork() Crash

Spring Fork Crash on Ruby on Rails

Working with legacy Ruby on Rails applications is for most developers a problem, as they have a lot of extra work to do:

First of all, many developers will hit the CPU architecture change from x86/x64 to ARM64 using Apple Macs. Even installing older Ruby versions on a newer OS (operating system) on a x86/x64 architecture is hard. It produces a lot of problems, warnings, and errors.

Analyzing SassC::SyntaxError in Ruby on Rails 7.0

SassC::SyntaxError in Ruby on Rails

I was running a up to date Ruby on Rails 7.0 project using cssbundling-rails. The project was in production for several months. After pushing the code to Continuous Integration (CI) using GitHub Actions it failed with an error:

Deploy Ruby on Rails 7.0 to Dokku micro PaaS

Dokku Website

This tutorial was tested with Dokku version 0.34.0

Deploying a Ruby on Rails application to a Dokku instance is pretty forward. There are only a few things you have to consider. In this guide, I will tell you, what might be the things and how to solve them. I was missing a complete guide with explanations aligned to the deployment of a default Ruby on Rails application.

Fixing require LoadError as an example for the matrix gem

cannot load such file matrix LoadError

Some gems like matrix or rexml were added at some point to ruby becoming so-called default gems. But they may be removed from being default in newer ruby versions, resulting in broken builds like for us with prawn:

Fix Flaky Rails System Tests caused by slow scrolling or animations

Chrome and Chromium Smooth scrolling flag

Flakiness on browser-based system tests (integration tests) in Ruby on Rails may have a lot of different reasons. One is scrolling, which may be slowed down by browser setup (smooth scrolling), JavaScript callbacks which result in some kind of events like for animations, etc.

Howto migrate from Webpacker to jsbundling-rails in Ruby on Rails

Using jsbundling-rails for JavaScript pipeline

A lot of Ruby on Rails applications created with Ruby on Rails version 5.x or 6.x or even upgraded from the previous versions are using webpacker as their primary asset pipeline. But now as webpacker has retired, it is time to move on. jsbundling-rails is or will be the most obvious step to go. Don’t try to move to importmap-rails directly, as you may encounter more problems you have to solve.

Howto migrate from Webpacker to cssbundling-rails in Ruby on Rails for CSS

Using cssbundling-rails for CSS pipeline

A lot of Ruby on Rails applications created with Ruby on Rails version 5.x or 6.x or even upgraded from the previous versions are using webpacker as their primary asset pipeline. But now as webpacker has retired, it is time to move on. cssbundling-rails is or will be the most obvious step to go.

Howto remove sprockets-rails from you Ruby on Rails project

Remove Sprockets from Ruby on Rails

Before removing sprockets-rails from dependencies of your Ruby on Rails project, check whether you are surfing images or fonts using sprockets through assets paths like:

… or any other assets except Style Sheets (CSS):

If you are using cssbundling-rails the sprockets default path for Style Sheets is used by default:

Define Default URL for ActiveStorage to fix Mixed Content Error

Using ActiveStorage with external services like AWS S3 for saving and surfing attachments like images is great. The setup is well explained in Active Storage Overview in Ruby on Rails Guides.

But if you start using it, you will maybe encounter some problems, which are not that easy to find or debug, as they mostly appear in production. One of the problems we encountered was a Mixed content related to ActiveStorage. This was not a big problem at first, as you get only a warning in a browser with default configuration. But after we added an iOS App, which was using WkWebViews, some random redirects to AWS S3 images stopped working. We couldn’t even see connections for these images to ActiveStorage endpoint of our Ruby on Rails Application in logs, which made it harder to debug.