The RailsNotes Newsletter 🟥 ISSUE #14

🟥 ISSUE #14 (Rails 7.1 released, RailsWorld, Dockerfiles, ActiveRecord Normalizes)

Dockerfiles! They’ve finally come to Rails 🐳

Welcome to The RailsNotes Newsletter — Issue #14! This issue is all about what’s new in Rails 7.1!

RailsWorld is well underway (my Twitter feed is proof enough of that 😅) and Rails 7.1 has been released! I’ve dedicated this edition to covering the new stuff, since it’s packed with some great headline features — Dockerfiles, improvements to hand-rolled authentication, Bun support and more. 

With Rails 7.1 comes some great nice-to-haves too — the new Rails.env.local? helper, view template locals, open range support for .in? and more.

To me though, the most exciting stuff from RailsWorld is actually news on what’s coming! Just take this slide from @marcoroth_ (so hyped 🔥) —

StimulusLSP looks unreal, and the rest of that slide is just ❤️‍🔥 so good 🤌.

If you’ve been following RailsWorld and Rails 7.1 news, then you’ve probably seen some of the stuff I cover here. I’ve included some lesser-known additions further down; I’m sure there’s something to learn here for everyone.

In other news, I’ve updated RailsNotes UI to support custom fonts! Now you can build more creative and interesting email templates.

Rails 7.1 is the name of the game though, so let’s dive in!

~~~ FEATURED ARTICLE ~~~

You, securing your Rails app using only the new built-in authentication parts of Rails 7.1!

This is the official announcement post for Rails 7.1, featuring a breakdown of the major highlights — Dockerfiles, auth improvements, async queries, composite primary keys, and much, much more.

It’s definitely worth a read, as is the detailed release info (see next paragraph). As with every Rails release, there are heaps of small tweaks and changes that have been merged in, but don’t warrant an announcement or blog post. I’m talking about things like —

  • Adding timestamptz support for Postgres databases (nice one Alex 😉)

  • Specifying multiple fixture paths with TestFixtures#fixture_paths

  • Adding support for Array#intersect? to ActiveRecord::Relation

  • Literally hundreds of other changes!

You can check out the official release notes for a breakdown of most changes, or if you’re feeling up to it, dig through the GitHub release info to see everything new.

— SPONSOR —

Put Artificial Intelligence in the pilot’s seat. With Tech Vetting you’ll always choose the best candidate, thanks to our set of automated interviews, cost-effective hiring, quick decisions and no scheduling conflicts!

So say goodbye 👋 to those complicated skill assessments!

Ready to accelerate your tech hiring? Try Tech Vetting! →

~~~ MORE ARTICLES  ~~~

Here’s another cool new Rails 7.1 addition — normalized columns! Model files now support normalizes:, which is a handy way to sanitize input, and keep your database clean and consistent.

Copying directly from the article, in Rails 7.1, you can write code like this —

class User < ActiveRecord::Base
  normalizes :email, with: -> email { email.downcase }
end

(Also, can I say — MintBit, your blog is beautiful ❤️)

It’s no secret that PostgreSQL is the database-darling of the Rails world. Not everyone uses it though. For instance, GitHub runs mysql, and Trilogy is the release of their new mysql database adapter.

The article itself dives into why GitHub released a new adapter (spoiler: performance). It also includes some hidden gems, like the joke embedded in the name Trilogy — “The name is a pun: it’s the third adapter GitHub has used, and it’s used to query sequel.”

Here are some PRs for you to read! (It’s OK, I’m not asking for a code review 😉). This one introduces the perform_all_later method to ActiveJob, drawing on the existing push_bulk method from Sidekiq.

This should be a great help in cases where you have heaps of jobs to enqueue at once — Your app will just hit Redis once, and skip callbacks, keeping things snappy.

Also, as a bonus, here’s another great PR (and something I’ve personally been hoping to see) — Allow templates to define which locals they accept.

~~~ ⚒️ HANDY TIP ~~~ 

→ Use Rails.env.local? to test if you’re in a production environment

A super small addition to Rails (from DHH), but another classic “nice to have”, Rails.env.local? is a shorthand for .development? || .test?.

It’s is a cute way to clean up your code —

# Add Rails.env.local? 
# short for Rails.env.development? || Rails.env.test?.
#- DHH

# ✅
if Rails.env.local? do 
  ...
end

# ❌
if Rails.env.development? or Rails.env.test? do 
  ...
end