#​590 — February 10, 2022

Read on the Web

Ruby Weekly

Rails and Its Ruby 'Dialect' — Originally sporting a title of “Rails is not written in Ruby”, this post makes the point that Rails' choices hugely impact what we consider to be 'Ruby' while using it. While many Rubyists think that monkeypatching is troublesome, we (nearly) all still use Rails and ActiveSupport to some extent, accepting the “magic” that they bring for convenience. Peter pushes for composition, giving examples of libraries today that do it right.

Peter Solnica

Papercraft: Composable Templating for Ruby — Papercraft (which supports HTML, XML, and JSON) sets itself apart from other templating gems by making everything a proc, allowing easy and clear composition of templates. Reminds me of _why’s Markaby from back in the day, but goes further with the idea.

Sharon Rosner

🐘 The Developer Experience You Always Wanted for Postgres — Database as a service for Postgres as it should be. Cloud agnostic, superuser access, performance tuned instances, and packed with all the extensions you need. From the Crunchy Data team that’s 100% focused on Postgres at any scale. Try it today.

Crunchy Bridge sponsor

IN BRIEF:

▶  Exploring Ruby’s Set Class — A quick 11-minute video that will definitely teach you something new about the Set class and when you should reach for it over other collections.

Tay DeHerrera Jimenez

Rails 7.0.2 Released — Only a tiny point release, but with some noteworthy changes nonetheless, including database schemas now being versioned with the current Rails version and no longer being able to pass service_name to DirectUploadsController

Rafael Franca

Jobs

Backend Engineer | Remote within CET (-3/+3 hours) | Full-Time — Europe's leading business finance solution. You will help us simplify everything from everyday banking and financing, to bookkeeping and spend management.
Qonto

Senior Rails Engineer @ Nebulab (Remote) — Join our distributed team and build high-volume eCommerce applications in a workplace made by developers for developers.
Nebulab

Find Ruby Jobs Through Hired — Create a profile on Hired to connect with hiring managers at growing startups and Fortune 500 companies. It's free for job-seekers.
Hired

📕 Articles & Tutorials

Using AWS S3 for File Storage in Rails Apps — Amazon’s S3 provides an essentially infinite way to scale your file storage (if you ignore the monthly bill..) and using it to store assets for a Rails app isn’t too complicated.

Jeffrey Morhous

Reusing Rails Test Fixtures for db:seed“If you always skip fixtures for factories when working with Rails, you are missing out!”

Josef Strzibny

'The Software and Infrastructure We Use to Run Our SaaS' — I always like a look behind the scenes at what stacks companies are using day-to-day. Rubyist Andy Croll shares his company’s approach here with, unsurprisingly, Rails at the heart.

Andy Croll

Project Management for Software Teams Has Never Been Easier

Shortcut (formerly Clubhouse.io) sponsor

▶  Hotwire Modals — An unobtrusive and efficient way to launch Bootstrap modals using Turbo and Stimulus.

David Kimura

▶  Discussing GitHub Codespaces and Docker with Benjamin Wood — If you’ve not used Codespaces yet, you can get a Rubyist’s take here.

Remote Ruby podcast

Quick Tip: How to Display the Current Environment in Rails' Console Prompt
Paweł Urbanek

TIL: ActiveRecord Transactions Roll Back on Thread Abort
Ben Sheldon

🛠 Code & Tools

Strong Migrations 0.8: Catch Unsafe Migrations in Development — Detects potentially dangerous operations and prevents them running by default.

Andrew Kane

Arbre: A Way to Build HTML Views in Ruby Code — Billing itself as an ‘object-oriented DOM tree in Ruby’, Arbre is extracted from the Active Admin Rails admin framework.

Active Admin

Get Stripe-Quality Webhooks for Your App in Minutes, Not Days — Skip the grunt work and let Hook Relay manage your webhooks for you. Visualize Stripe-quality webhooks for your app — make it a reality in minutes.

Hook Relay sponsor

Win32::Screenshot: Capture Screenshots on Windows from Ruby — It uses FFI to directly call the relevant functions in the Windows GDI system (here's the code at the heart of that operation, if you're curious about calling Win32 APIs from Ruby).

Jarmo Pertman

Awesome Nested Set: The Nested Set Pattern for ActiveRecord Models — Billed as a replacement for acts_as_nested_set and BetterNestedSet, this now supports Rails 7.

Collective Idea

AnnotateModels: Annotate Code with ActiveRecord Model Schema Info — Having schema info at the top of your model files, say, could be handy for quicker referencing while developing.

Cuong Tran

Dart Sass for Rails: Integrate Dart Sass with the Rails Asset Pipeline
Ruby on Rails

CreateSend 6.0: A Ruby Library for the Campaign Monitor API
Campaign Monitor

Announcing Hanami v2.0.0.alpha6
Luca Guidi

💡 Tip of the Week



Binstubs

Have you ever griped about constantly having to type bundle exec before running executables within a Ruby repo? For instance, bundle exec rubocop or bundle exec rails s? We need the bundle exec to ensure we're getting the right version of whatever gem or executable we're running. But typing bundle exec continually can be cumbersome. And there could be unexpected version inconsistencies if we forget it.

Binstubs to the rescue! Many Ruby apps we use will already have a bin directory containing binstubs. Rails applications, for instance, are initialized with a few binstubs, including bin/rails.

Binstubs wrap around executables to ensure we're running the right version of a gem. This means that, for instance, instead of running bundle exec rails server, we can run bin/rails server, and get the same result.

Okay, so Rails will generate some binstubs for us, but what about gems which don't have autogenerated binstubs, or if we're not in a Rails repository? We can always run bundle binstubs <gem_name> and bundler will generate the binstub for us. For instance bundle binstubs rubocop will generate bin/rubocop, and then instead of running bundle exec rubocop, we can simply run bin/rubocop.

You might be reading this and thinking "bin/rubocop" is still cumbersome, why can't we just run rubocop? Turns out, we can set ourselves up so we only need to run rubocop. More on this next week!

This week’s tip was written by Jemma Issroff.