The RailsNotes Newsletter 🟥 ISSUE #20

🟥 ISSUE #20 (POROs, OO Design, Black Friday Deal 🤑 and more!)

Thank you DALLE-3 for “punk rock giga-chad” Ruby characters 😂 

— SPONSOR —

Efficient Search in Rails with Postgres — Speed up a search query from seconds to milliseconds and learn about exact matches, similarity matches with trigrams, partial matches with ILIKE, and natural language full-text search.

Welcome to The RailsNotes Newsletter — Issue #20! In this issue, we’re talking POROs!

Big week! Lots of Black Friday sales in the Ruby on Rails world (here’s a handy Reddit post with quite a few of them), and Tobi Lutke (Shopify founder/CEO) just tweeted about the bonkers traffic that the Shopify Rails monolith has been handling (maybe… Rails does scale?! 😅 ).

This week’s newsletter is about POROs (plain old Ruby objects). I found myself leaning into them a bit more at work and in my side projects over the last few weeks (driven in part by some recent reading). I thought it would be a fun Rails-adjacent topic to dig into.

Side note: I’m a bit late with the newsletter this week (oops 😅 ) but in case you missed my tweet, you can get 40% off my Ruby on Rails email templates and components, RailsNotes UI, as part of my Black Friday sales. Just use the offer code SHORT40 when you checkout!

Side-side note: I’ve added a referral program to this newsletter! Share it around and earn some sweet rewards, and big thank-yous from me (more info at the end of this email!)

Finally: This is the last issue of PgAnalyze’s sponsor spot — make sure to check out their free PostgreSQL search ebook! This one covers building full-text searches with plain Rails and PostgreSQL, and as usual, it’s got great diagrams like this one below to explain things — 

One of the many cool and handy illustrations that PgAnalyze loves to include in their eBooks.

If you’re interested in sponsoring the newsletter, you can check out the advertising blurb or email [email protected] directly!

Enough said, let’s go!

~ FEATURED ARTICLE ~

POROs are the secret that other Rails devs /really want you/ to know!

It was tricky picking the featured article for this week! I think all the articles in this newsletter can teach you some part of the PORO whole, but I chose to feature this article for a few reasons. For one, Steve includes heaps of code samples, which he uses really effectively in explaining some of the PORO benefits.

For another, I like his writing style (simple and engaging), and the domain itself (extracting presentation logic out of a model, and into a Presenter) are a great illustration of the broader PORO concept.

Enjoy the article!

~ MORE ARTICLES  ~

A great article from a great Ruby on Rails blog! Jason runs through a refactoring of a real, hairy, ugly Rails model, and uses loads of code examples to explain along the way.

I think it’s a great before/after of a Model after it’s been PORO-ified, and a great look at how to actually use a PORO in a Model! (which is where you’ll probably benefit from them the most!)

Justin’s written another great PORO article; specifically, he dives into Service Objects and Presenters, two typical PORO candidates (since otherwise, these things end up getting lumped into your models).

His code examples are clear and simple; This is probably the easiest/shortest read, and is a great place to start!

This is a great end-cap to the other articles here and wraps up some of the info in the other articles.

It’s more of a summary of a great Reddit question/answer pair, but still a good article to end on.

~ ⚒️ HANDY TIP ~ 

→ Use ActiveRecord Validation Contexts to group model validations

Not really related to POROs (sorry 😅 ) but I was on the Ruby on Rails subreddit today and learned something really cool from this thread.

You can pass on: to your Model validations to only run them in a specific context (more info in the docs), a bit like in this example here — 

class User < ApplicationRecord
  # Custom validations under :admin context, using on:
  #
  validates :admin_email, presence: true, on: :admin
  validate :ensure_admin_email_domain, on: :admin

  def ensure_admin_email_domain
    unless admin_email&.ends_with?('@abc.com')
      errors.add(:admin_email, '...')
    end
  end
end

user = User.new(name: 'John', email: '[email protected]', admin: true, admin_email: '[email protected]')

# This will run the standard validations
# Returns True
#
user.valid?

# This will run standard AND admin-specific validations
# Returns False (wrong admin email domain)
#
user.valid?(:admin)

Just saw this and thought it was cool! Blew my mind a bit 😅 🤯 

~👀BEHIND THE SCENES~ 

This is a private section 🔐 for readers with 2+ referrals!

I share behind-the-scenes updates on RailsNotes and RailsNotes UI (think traffic numbers, sales, upcoming updates etc.)

Want access? Learn about the referral program down below! 👇️ 

My first behind-the-scenes section! I get the feeling I’m the only person who’ll actually see this, but it’s still fun to write and share the stats a bit.

If you’re reading this, you’re one of the first people to hear that I’m working on something new! RailsNotes UI is currently just email templates and components, but I’ve always planned to branch out. I’m planning for that first new ‘branch’ to be a developer-focussed Ruby on Rails SaaS template!

There are already a bunch of SaaS templates, but I’ve never used them and never will. I realised they all either — 

  1. Do too many things that I don’t care about, or don’t want to think about (teams, complex billing, admin panels etc). RailsNotes UI doesn’t even have password resets yet, and it’s doing great!

  2. They’re too expensive. There’s just no way that I’d spend $300+ on a starter template, which is where others like Jumpstart and BulletTrain price themselves.

I’m planning for my template to be more affordable (less than $50), handle the basics (and handle them well!), and then get out of your way! (core basics like Devise auth + OAuth + Password Resets, Billing with Stripe/LemonSqueezy, and deployment). Basically, I’m building the Ruby on Rails starter template that I wish existed. Here’s the first-ever public screenshot 😱 

~ 🌯 WRAP UP ~ 

Thanks for reading! In case you missed it above, don’t forget that — 

  1. POROs are a handy tool to have in your back pocket! They dovetail 🕊️ well into certain situations and can help clean up your code.

  2. RailsNotes UI is having a sale until the end of November. Use the offer code SHORT40 to get 40% off!

  3. This newsletter now has a referral program! Show me your support by referring people to read my newsletter (using your special link), and get cool rewards (I’m also very open to feedback if you think the rewards are, actually, not cool 🙃 )

Share the RailsNotes Newsletter!

Refer your friends/co-workers/brother/sister/goldfish 🐟️ (using your unique link below) to support this newsletter. I’ll reward you with coupon codes, and access to the private behind-the-scenes section (plus big thank-yous from me along the way! 🙌 ).

  • [Refer 1] A small feature in the next newsletter (with a link to something you’re working on, or your socials)

  • [Refer 2] Permanent access to the behind-the-scenes section, above 👆️ 

  • [Refer 5] A $20 coupon for RailsNotes UI 📬️ 

  • [Refer 15] Free licence key for RailsNotes UI 🤑