---
title: "Some advanced Active Record concepts"
publication: "Ruby Weekly"
issue: 651
published_at: "2023-04-27"
canonical_url: "https://rubyweekly.com/issues/651"
---

Plus ViewComponent 3.0, and a tip on generating your own local certificates for fake domains. |        

#​651 — April 27, 2023 

[Read on the Web](https://rubyweekly.com/issues/651)  

Together with [![AppSignal logo\](https://res.cloudinary.com/cpress/image/upload/c_fill,g_auto,e_trim,w_700,h_120/e_make_transparent/co_white,e_outline:7/lme8p344dw1aodshz9px.png)](https://www.appsignal.com/ruby/sidekiq-monitoring?utm_source=ruby-weekly-sponsored&utm_medium=email&utm_campaign=2023-21-04)  

Ruby Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60,q_auto/k7w2bneta0vxyi4jbvv8.jpg)](https://evilmartians.com/chronicles/mrsk-hot-deployment-tool-or-total-game-changer)  

[MRSK: Hot Deployment Tool to Watch—or Total Game Changer?](https://evilmartians.com/chronicles/mrsk-hot-deployment-tool-or-total-game-changer) — The Evil Martians team gives DHH’s new container-based MRSK deployment tool a ‘vibe check’. The conclusion is that it has potential but there are various things to weigh up before you switch boats. 

Evil Martians   

🚢 In related news, the [official MRSK homepage](https://mrsk.dev/) at [MRSK.dev](https://mrsk.dev/) has lost its original brutalist design and now looks slick and ready to sail. There's a 20-minute screencast introduction from DHH to enjoy as well.  

[Some Advanced Active Record Concepts](https://blog.rubyhero.dev/advanced-active-record) — Quick examples of concepts including locking records to avoid conflicts, using UUIDs as primary keys, fulltext search, using database views, and working with geospatial data. 

Paweł Dąbrowski   [![\](https://copm.s3.amazonaws.com/3f690d34.png)](https://www.appsignal.com/ruby/sidekiq-monitoring?utm_source=ruby-weekly-sponsored&utm_medium=email&utm_campaign=2023-21-04) 

[Smooth and Powerful Sidekiq Monitoring](https://www.appsignal.com/ruby/sidekiq-monitoring?utm_source=ruby-weekly-sponsored&utm_medium=email&utm_campaign=2023-21-04) — Track and debug Sidekiq performance metrics with ease. Get insights and alerts for Sidekiq queue lengths, Sidekiq throughput/performance per worker, and Sidekiq process/connection counts. 

AppSignal sponsor   

[How Ruby's 'Switch' is More Flexible Than You Thought](https://www.akshaykhot.com/ruby-switch-statement/) — It might be `switch` in C, but in Ruby it’s `case` and offers a lot more than just being syntactic sugar for `if`/`else` constructs. Akshay shows off some of its extra features. 

Akshay Khot   

[Stop Ignoring Your Ruby and Rails Deprecations (and How)](https://blog.testdouble.com/posts/2023-04-24-stop-ignoring-your-ruby-and-rails-deprecations/) — No-one wants to see warnings and it’s tempting to skip over them, but they’re there for a reason. Ali explains how deprecation warnings can help you upgrade your app before you _really_ upgrade your app (which can help a lot when upgrading Rails versions in particular), and shows off of a technique for formally making deprecations part of an app’s reality. 

Ali Ibrahim   

**QUICK BITS** 

- Amanda Perino, the executive director of the _Rails Foundation_, [▶️ went on the Ruby on Rails podcast this week](https://www.therubyonrailspodcast.com/467) to talk about the foundation's work. She went [▶️ on _Remote Ruby_ too.](https://share.transistor.fm/s/dc4bcbee)
- 📕 To celebrate RailsConf, Noel Rappin, the new 'Pickaxe' / _Programming Ruby_ author, is offering 35% off on [the 5th edition of _Programming Ruby 3.2_](https://pragprog.com/titles/ruby5/programming-ruby-3-2-5th-edition/) at Pragmatic Bookshelf until May 5 with code `RailsConf_Atlanta`.
- 🇷🇴 Good news. The new _Friendly.rb_ conference taking place in Romania this September is [all set to go ahead](https://friendlyrb.com/blog/friendly-rb-is-still-on) despite some minor hiccups. It's also looking for sponsors.  

📕 Tutorials, Articles, and Videos  

[Updating Millions of Records in Rails](https://blog.eq8.eu/til/update-millions-of-records-in-rails.html) — Ideally you’d step down to the database layer and avoid the overhead of Active Record entirely when doing large numbers of updates, but if that’s not viable, this is a reasonable Ruby-based approach based around Sidekiq and updating records in batches. 

Tomas Valent   

[Making Lazy Accessors Thread-Safe](https://www.gregnavis.com/articles/making-lazy-accessors-thread-safe.html) — Greg created a gem called [Feature Envy](https://github.com/gregnavis/feature_envy) that pulls in features from other languages. In this case, he creates thread-safe, lazy attributes in Ruby, which is more involved than you might expect. 

Greg Navis   

[How to Use OmniAuth to Add Authentication to Your Ruby App](https://fusionauth.io/docs/v1/tech/tutorials/integrate-ruby-rails?utm_source=rubyweekly&utm_medium=newsletter&utm_campaign=omniauth-integration) — Check out this strategy that leverages the OmniAuth gem and OIDC to add log in to your application with FusionAuth. 

FusionAuth sponsor   

[Build a Memory Game with Rails, Stimulus JS, and Tailwind CSS](https://semaphoreci.com/blog/memory-game-rails-stimulusjs-tailwindcss) — This is a good old step-by-step tutorial, with much of the focus on Stimulus and how it can be used to incrementally add functionality to Rails apps. 

Marvin Kang   

[The Hardest Question on a Ruby Array Quiz](https://www.vector-logic.com/blog/posts/hardest-question-on-ruby-arrays-quiz) — Only 2.07% of participants in a recent quiz got this one right – mostly because of not knowing the default no-argument behavior of `split`, I suspect. This is all really just trivia, but I did learn that `Array#sum` does _not_ only act upon numeric objects.. 

Domhnall Murphy   

[Solving N+1 Postgres Queries for Rails Apps](https://www.crunchydata.com/blog/postgresql-for-solving-n+1-queries-in-ruby-on-rails) — Tips for working with ActiveRecord and using better SQL to improve performance and avoid N+1 queries. 

Christopher Winslett   

[Rails 7, Bootstrap CSS, and JavaScript with esbuild](https://ryanbigg.com/2023/04/rails-7-bootstrap-css-javascript-with-esbuild) — How to introduce Bootstrap into an existing Rails 7 with [esbuild](https://esbuild.github.io/) handling the bundling. 

Ryan Bigg   

▶[Writing 'Boring' Code with the Help of ChatGPT](https://avdi.codes/writing-boring-code-with-the-help-of-chatgpt/) — Avdi is well known as a Ruby developer who runs the [Graceful.dev](https://graceful.dev/) screencast site, so it makes sense he might turn to ChatGPT when using a less.. engaging language like PHP. 😆 

Avdi Grimm   

[Why Duplication is More Acceptable in Tests](https://www.codewithjason.com/why-duplication-is-more-acceptable-in-tests/) — DRY isn't the only way. 

Jason Swett   

[Containerize a Rails 7 App and Run it on Vultr with Cloud 66](https://blog.cloud66.com/containerize-a-rails7-app-and-run-it-on-vultr-with-cloud66) 
Kasia Hoffman (Cloud 66)   

[Seven Common Mistakes in Rails Upgrades](https://www.fastruby.io/blog/rails/upgrades/7-common-mistakes-made-while-doing-rails-upgrades.html) 
Rishi Jain (FastRuby)  

🛠 Code & Tools 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60,q_auto/d0xvq9pgwdvcaq5a9acw.jpg)](https://viewcomponent.org/)  

[ViewComponent 3.0: React-like View Components for Rails](https://viewcomponent.org/) — A framework for building reusable, testable & encapsulated view components in Rails, inspired by React. [v3.0](https://github.com/ViewComponent/view_component/releases/tag/v3.0.0), a pretty significant release featuring work from over 200 contributors, was unveiled at RailsConf earlier this week. 

ViewComponent Contributors   

[Low Cost, Rails Code Audit by a Senior Dev](https://reinteractive.com/services/app-review) — We rapidly review your app using a nine point audit including security, tech debt, performance, versions and code quality with full recommendations on each. 

reinteractive Pty Ltd sponsor   

[FastCount: Quickly Get a Count Estimation for Large Tables](https://github.com/fatkodima/fast_count) — Requires Active Record 6+. Mostly benefits Postgres users (via [this approach](https://github.com/fatkodima/fast_count/blob/master/lib/fast_count/adapters/postgresql_adapter.rb)), but will transparently work with MySQL, MariaDB, and SQLite too. 

fatkodima   

[Maxitest 4.4: Minitest, Plus All The Features You Always Wanted](https://github.com/grosser/maxitest) — [Too many features](https://github.com/grosser/maxitest#features) to list here, to be fair. 

Michael Grosser   

- [Alba 2.3](https://github.com/okuramasafumi/alba)
 ↳ Fast, feature-rich JSON serialization.
- [Ruby OpenAI 4.0](https://github.com/alexrudall/ruby-openai/releases/tag/v4.0.0)
 ↳ Now supports _streaming_ chat responses.
- [Lamby 4.1](https://github.com/customink/lamby)
 ↳ Rails and AWS Lambda integration option.
- [rswag 2.9](https://github.com/rswag/rswag)
 ↳ Adds a Swagger to Rails-based APIs.
- [Steep 1.4](https://github.com/soutaro/steep) – Static type checker for Ruby.
- [Tomo 1.16](https://github.com/mattbrictson/tomo) – CLI for deploying Rails apps.
- [ruby-pg 1.5.2](https://github.com/ged/ruby-pg) – Postgres client library.
- [Ruby JSON Schema Validator 4.0](https://github.com/voxpupuli/json-schema)
- [Rack 2.2.7](https://github.com/rack/rack)      

💬 Tip of the Week
Using a 'fake' domain with SSL locally
via Khash Sajadi of [Cloud66](https://blog.cloud66.com/running-rails-development-with-a-fake-domain-and-ssl)   

If you want to test a feature that not only requires SSL/TLS but also a custom domain of your choice, and all on a locally running app, there are a variety of ways to achieve this. An approach I really like is using `mkcert` and [Caddy.](https://caddyserver.com/) 

On macOS, it's as simple as this: 

```
brew install mkcert
brew install nss # if you use Firefox
brew install caddy
``` 

_(Note: If you're using Linux, [use these instructions instead.](https://github.com/FiloSottile/mkcert#linux))_ 

Then you can install `mkcert` and generate the certificate of your choice like so: 

```
mkcert --install
mkcert app.acme.com
``` 

`mkcert` creates certificates against a local-only certificate authority that your browser will recognize, allowing you to create and sign against any domains of your choice. A `Caddyfile` will then act as the HTTP server terminating the TLS connection and serving up the certificate: 

```
app.acme.com
reverse_proxy localhost:3000
tls app.acme.com.pem app.acme.com-key.pem
``` 

Then you need to add a line like `127.0.0.1 app.acme.com` to your `/etc/hosts` file, run your app in the usual way, and then run `caddy run` for everything to spring into action. _(Note: If your app server runs on a different port to 3000, you can update that in the `Caddyfile` above.)_ 

Note: This is just a quick recap for _Ruby Weekly_ but you can find the complete blog post at [Running Rails Development with a Fake Domain and SSL](https://blog.cloud66.com/running-rails-development-with-a-fake-domain-and-ssl) on the _Cloud 66_blog.       

Jobs  

[Find Ruby Jobs with Hired](https://hired.com/join/?utm_source=newsletter&utm_medium=sponsor&utm_campaign=%28b2c%29%28l-all%29%28r-all%29%28cooper-rubyweekly%29&utm_content=easy-job-hunting) — Hired makes job hunting easy-instead of chasing recruiters, companies approach you with salary details up front. Create a free profile now. 
Hired           

Curated by [Peter Cooper](https://twitter.com/cooperx86) and [Glenn Goodrich](https://twitter.com/ruprict).
Published by [Cooperpress](https://cooperpress.com/). 

[Change your email](https://rubyweekly.com/edit_subscription/*|UID|*) or [Stop getting this newsletter.](https://rubyweekly.com/leave/*|UID|*) 

© Cooper Press Ltd · Fairfield Enterprise Centre, Louth, LN11 0LS, United Kingdom   

Other weekly newsletters we publish include [Postgres Weekly](https://postgresweekly.com/), [React Status](https://react.statuscode.com/), [Frontend Focus](https://frontendfoc.us/), and [JavaScript Weekly](https://javascriptweekly.com/).
