🧐 Issue #13 - 03 - 09 October 2022

The one where we share our love of Ruby and Rails

If you want a short excerpt of this newsletter containing only some of the images with code, I created one here. But I invite you to read the entire newsletter as it has excellent content 😊.

This edition was created with support from @adrianthedev from Avo for Ruby on Rails (a friendly full-featured Rails admin panel) and from @jcsrb, who sent me recommendations to include in the newsletter.

👉 Jason Charnes asked what excites people about Ruby on Rails in 2022:

I need input from the community. What excites you about Ruby on Rails in 2022?

Here are some answers:

  • “The community. To be more specific the freshness and joy of Ruby 3 and Rails 7 that I think is fueling an excitement of the community and a desire to attract new people in the community” (@lucianghinda)

  • “Hotwire. Wish Rails would offer a PWA solution out of the box.” (@th1agofm)

  • “Alternative ruby frameworks to Rails. Which ironically strengthens the rails and Ruby a lot.” (@kowfm)

  • “The error reporter interface became more mature and adoptions are increasing” (@_st0012)

  • “Rails 7 changing the game and getting us back to our roots. It has me so dang excited. Not just what hotwire delivered but a renewed excitement in the framework and the fundamentals that made us love it in the beginning.I love writing rails so much” (@schwad_rb)

  • “Hotwire! One codebase, instead of Rails API + gigantic pile of JS. I can maintain a Rails+Hotwire app myself, much harder to maintain both Rails API and React frontend by myself” (@aidanhmiles)

  • “Feels like anyone can become a one man coding machine with Hotwire. I wasn’t even doing frontend until Hotwire. Didn’t have the interest before then because I found it a nightmare. Now, it’s the most fun I have had in years!!” (@mhenrixon)

  • “That my lack of interest in learning a lot about React in recent years...might be paying off.” (@robbyrussell)

  • “For me it’s the basics. That it’s a solid platform with a good, supportive community that makes it easy to build cool things!” (@rose_w)

  • “Particularly for prototyping a new app for feature, it's still the best way to do it by a significant amount. That's still, to me, the big problem Rails solves very well that nobody else is really trying to solve.” (@codefolio)

  • “the additional focus from the community on helping juniors, learning and teaching ❤️, things like new podcasts, courses, newsletters etc.” (@afomera)

  • “Just how easy it is now to build high-fidelity user experiences in Rails with Hotwire, custom Turbo Stream actions and the myriad of possibilities they enable, CableReady::Updatable, etc.” (@danieldopence)

  • “The fact that our _entire_ [2 person 🤪] bonsai product team can be very productive in shipping entire vertical slices of work. I love that I don't have to slide in at the end of a wip PR and add large javascript components to do basic front end fanciness.” (@allizad)

There are a lot more anwers. You should read all the replies.

👉 Postmodern shared that pdfkit-0.8.7 still has the problem described in CVE 2022-25765:

ATTN: CVE 2022-25765 which effects the pdfkit ruby gem was thought to be patched in pdfkit-0.8.7 and temporarily marked as patched in ruby-advisory-db, but that does not appear to be the case. All versions of pdfkit are now re-marked as vulnerable!

To check if you have this issue:

👉 Postmodern asked a question about difference between accessing ENV variables:

Can someone explain why Rubocop suggests `ENV.fetch('FOO',nil)` over `ENV['FOO']`. They are equivalent, no?

In case you are wondering how does ENV behave when using with fetch or access through []:

And it seems the reason Rubocop suggest this change is to make the default value implicit.

👉 David shared a code sample about setting order with condition in Rails:

How to order Posts by the `draft` status and then by title ignoring any other status. #rubyonrails

👉 Greg Navis shared a code sample about marking active models as read only:

💡 Rails tip: models can be marked read-only to ensure no changes are made. Useful for: ✅ Reporting ✅ Integrating with legacy code (to prevent it from messing up stuff)

👉 Akshay shared in thread the difference between class_eval and instance_eval in Ruby:

The difference between class_eval and instance_eval in Ruby

👉 Kirill Shevchenko shared a code sample showing how reverse_each works in Ruby:

Ruby has a reverse_each method that allows you iterate an array backwards. Moreover, it's faster than just calling reverse method on array before iterating, because reverse_each doesn't create a new array.

👉 David shared a comparison between dom_id and turbo_frame_tag:

🤦‍♂️I assumed that `turbo_frame_tag` constructed an `id` using the `dom_id`. It does use `dom_id` but it `maps` the arguments, trying `dom_id` and joins them with a `_` #rubyonrails

👉 Thiago Massa shared a code sample of using pattern matching in Ruby 3.1:

Have you tried pattern matching yet in Ruby? Here I am to remind you, as I believe it's one of Ruby's coolest features! 🤯 I've created an example using all its features: variable pinning + find + destructuring. Hopefully, this can motivate you to try it out! 😁

👉 Joel Drapper shared a code sample about a new feature coming soon in Phlex, helping defining collection views:

Coming soon, you’ll be able to define “collection” views in Phlex with a collection template and an item template.

You can see mode Phlex code samples here, here and here. You can also browse a list of open source projects using Phlex at here.

👉 Greg Navis shared a code sample about how to disable lazy loading on individual instances of Active Record:

💡 Rails tip: disable lazy-loading associations via strict loading. ✅ No more surprise N+1 queries in deeply nested views. ✅ Total control over database queries and performance. ✅ Explicit is (sometimes) better than implicit (cough, Python, cough). RT if you find it useful

👉 Brad Gessler shared a code sample for getting all Rails tag helpers work with Phlex:

Playing with phlex.fun in Rails and needed to get all the Rails tag helpers working, so I ended up rolling this macro. This breaks encapsulation, but it’s fine because I only expose this at a Page & Layout level. Components don’t have access to these helpers. 🙅‍♂️

👉 Olatunbosun shared a code sample showing how to use pattern matching to DRY controller code:

Read the tweet, as there are more examples there.

👉 Adrian Marin shared a thread about how to think about Rails transitioning from Sprockets to today:

I was doing a pairing session with @lucianghinda trying to convert an older webpacker Rails app to esbuild & tailwind, and we noticed something. The mental model of this transition wasn't adequately communicated when the new packages were first introduced. #rubyonrails

👉 Samuel Williams shared a preview of a VScode extension - Sus Test Provider - that would provide real-time feedback when tests failed and the reason based on the sus - test framework:

Real time test feedback. The output position needs a bit more feedback, but it's basically working in real time as you edit the code. Sus being super fast, you barely notice it.

👉 Thiago Massa shared a sample code about Ruby safe navigation operator and dig:

Ruby is equipped with syntax and methods to avoid calling methods on nil values. Many beginners might not be aware of such constructs as the "dig" method and the safe navigation operator. But they are there for you. 🤗 Let's take a deep dive into them 👇

Bradley Schaefer replied with a piece of code showing a null object pattern for nested hashes:

👉 Greg Navis shared a Rails code sample about using some Active Record methods:

💡 Rails tip You probably know first, last, and others. But do you know about: 🟢 first(n) - the first n models 🟢 last(n) - the last n models 🟢 take(n) - any n models 🟢 take! - any model 🟢 sole - the only instance of that model Very useful in enforcing app-wide invariants.

👉 Kirill Shevchenko shared a code sample about debugging memory issues in Ruby:

If you have memory issues in your Ruby application, probably related to the number of some specific objects, you can use ObjectSpace to investigate them. #ruby

Joshn Cheek shared a piece of code that will show the source code and line number from where that objects was defined (the code can be found in this gist or a version that will also show the class name along with source code here):

👉 Jacob Daddario asked a question about organising code in a Rails app:

Where does everyone usually put their POROs? I know a lot of Rails apps have a services folder (not my preference). I sometimes organize by design pattern. That gets kind of silly sometimes though. Is lib an appropriate place for POROs?

Here are some answers from the replies, but I invite you to read them all as people share a lot of knowledge about what works and does not work for them and why:

On the same note, Jason Swett shared a twitter thread about code organisation:

To organize ALL files by type is to take what was a good idea at a certain level and apply it way beyond what makes sense.

What good could it possibly do to have all your factories in one folder, for example? What meaning or utility could that have?

Don't organize your Rails code by design pattern. Organize it by meaning.

👉 Peter Solnica shared they are playing with a new library codename dry-operation

👉 Thiago Massa shared a tweet about checking if a value if empty/nil/blank in Ruby on Rails:

Ruby on Rails has many ways to check if a given value is empty/nil/blank. I was browsing the web and found this very awesome table compiled by @mariaschuessler in an article. Awesome and daunting at the same time, isn't it?

👉 Akshay shared about the difference between proc and lamba when thinking about return:

A subtle difference between a proc and lambda in Ruby is how the `return` keyword behaves in each. In a proc, the return keyword returns from the scope where the proc was defined. In a lambda, the return keyword just returns from the lambda.

👉 Kevin Newton shared about the possibilities Ruby allows to define a class under a class that is inside a variable:

I can't help but wonder how much of the Ruby grammar is intentional and how much of it just happened over time. This particular ability feels really wild. You can define a class under another class/module that is housed in a variable.

👉 Kirill Shevchenko shared a code sample to daemonize a Ruby script:

f you need to daemonize a small ruby script in the background, you can do so with Process.daemon by adding it to the top of the file.

If you have read so far and you like the content, maybe you take into consideration sharing this and subscribing:

Related (but not Ruby specific)

🧐 Thiago Massa shared a useful terminal command: using !! to get the last command

Bang bang 💥💥 Have you ever used !! in your Terminal? If you typed a command and it is missing something (like an extra argument). You can use !! to expand into the last Command you had run. ✨ (like pressing up ^, but more flexible) Check it out 👇

🧐 Schwad shared a sample code for deleting all branches and keeping the main:

maybe I could alias "cleanmyroom" to `git branch | grep -v "main" | xargs git branch -D`

Mathieu Jobin replied with their Github repo named git-scripts containing a list of helpful scripts when working with git.

🧐 Xavier Noria shared a perspective about how meetings trigger “improvised action”:

You gotta think and give the necessary time to things. Also, meetings trigger improvised actions. I prefer async to let people sleep on ideas, and proper research beforehand as needed.

🧐 Brandon Weaver shared a nice tweet about what to focus when hiring:

Code is easy to teach, empathy is very much not. Hire for empathy first and foremost, the code will follow.

He also added:

Code is only hard because we don't talk to each other nearly enough, and assume that there's a technical solution to every problem.

🧐 Wisen Tanasa shared a thread about TDD and how to think about it:

Many of the software engineers I talked to told me that they practice TDD out of guilt. That's not right, we need a different way to think about TDD. I've been practising TDD for almost a decade, here's how I currently think about it:

Here is one of tweets in this thread:

🧐 Scott Hanselman shared a story about a friend dropping the production DB and it got some amazing replies with cool stories to read. It can happen to anyone:

A good friend of mine had a person on their team drop the production database this week. They are back up, but it was a scary 24 hours for them. Please quote tweet or reply to this thread with YOUR tales of #DroppingProduction so they know they aren't alone!

🧐 Julie asked as question about how to teach kids how to code:

Specifically asking the parents of #rubycommunity Do you teach your kids how to code? Why or why not? What do you use? What age did they start/do you want them to start? A bit overwhelmed by google and whats out there atm Thanks in advance!

There a lot of good answers in the replies that I invite you to read.

Articles and Videos

Courses/Books/Communities/Events

Bridgetown launched the announcement for BridgetownConf 2022, happening on 7 November 2022; it will be online and free. BridgetownConf 2022: Save the Date!

Julian Rubisch shared a preview of their new book Advanced CableReady. Get it on Gumroad

Something to read

🗞 Newsletters

🗞 Chuck Smith shared a new edition of Women on Rails Newsletter #36: The year of the crab, build trust while remote, create good Pull Requests. Read the English version, French version, Italian version, Spanish version

🗞 Greg Molnar shared a new edition of This Week in Rails written by Petrik de Heus. Read Updated Permissions-Policy directives and LSP support? 

🗞 Ruby Weekly published a new edition of their newsletter. Read Ruby Weekly 623

✍🏾 Articles

One Ruby Thing shared a new article about Time extensions. Read it at andycroll.com

Brandon Weaver shared an article they wrote about promotions. Read it at dev.to/baweaver

Lewis Buckley shared an article they wrote about running multiple Rails apps with Puma-dev. Read it at world.hey.com/lewis

Konnor Rogers shared an article they wrote about modifying the default rendering of attachments from actiontext. Read it at dev.to/paramagicdev

Paweł Dąbrowski shared an article they wrote about security best practices for Rails. Read it at blog.appsignal.com

Brandon Weaver shared a new article they wrote about Data.define in Ruby 3.2.

Ayush shared a new article they wrote about to render error pages through the Rails stack rather than from the `/public` folder. Read it at dev.to/ayushn21

Brad Gessler shared a new article they wrote about running Rails Background Jobs with Fly Machines. Read it at fly.io

Marco Roth shared an article they wrote about Custom Turbo Stream actions. Read Turbo 7.2: A guide to Custom Turbo Stream Actions

Adrian Marin shared a new article that they wrote about how Rails works with assets. Read New Rails asset compilation mental model

Something to watch 🎥 or listen 🎧

🎥 Videos

🎥 Ruby Learning Center shared the video they streamed for implementing Chapter 2 of Rebuilding Rails book. See Rebuilding Chapter 2

🎥 Drifting Ruby shared a new video about Hotwire introduction. See Hotwire introduction

🎥 Yaroslav Shmarov shared a new video they created where they show the power of rmagick with Ruby and Rails. See Rmagick to autogenerate images

🎥 Jared White shared a new video about HTML modules and going through the history of 25 years of web development. See The Rise (and Fall) and Rise Again of HTML Frameworks

🎥 Drifting Ruby shared the video version of This Week in Rails. See This Week in Rails - 2022-10-08

🎥 Adrian Marin shared a video presented by Norbert Wójtowicz at wroclove.rb 2022 about Grokking FP for The Practicing Rubyist

🎧 Audio & Podcasts

🎧 Joël Quenneville shared a new episode of The Bikeshed where he talks with Stephanie Minn about the value of specialized vocabulary and the power of names. Listen to The Value of Specialized Vocabulary

🎧 Jason Swett shared the final episode of Code with Jason where he talks with Nick Schwaderer. Listen to The Final Episode (for Now): Nick Schwaderer - The Code with Jason Podcast

🎧 Ruby For All published a new episode of Ruby for All: How to Get Feedback with Emily Samp. Listen to How to Get Feedback with Emily Samp

🧰 Gems, Libraries, and Updates

🧰 Petrik de Heus shared an open issue in Rails repository talking about adding —interactive to rails new in Rails 7.1. Read the ongoing discussion here.

🧰 There is also an open discussion in Ruby bug tracker abour import module. Read it here. It might (or might not) come in the next Ruby version.

🧰 Rubygems News shared a new gem named easytest: that “is a tiny testing framework for Ruby with a familiar DSL”. Here is how the code looks like:

🧰 Jean Boussier shared a (pre)version of pitchfork - a new Ruby HTTP server optimized for latency and memory usage. Check it out at GitHub - Shopify/pitchfork. Here is a short comparison between this server and Puma:

🧰 Stan Lo shared that there is a new release of IRB v1.4.2. Check the changelog at GitHub ruby/irb

🧰 Joel Drapper shared a code sample from a new gem called playdate. Hre is how the code might look like:

🧰 Josef Strzibny shared a new gem they discovered dogweather/asset_ram that helps with memoization of asset links, thus saving a lot of allocations per request.

🧰 Mike Perham shared that Sidekiq Pro 6.0b1 and Sidekiq Enterprise 3.0b1 are now available for testing with Sidekiq 7.0b1. Check upgrade notes here

🧰 David Teren shared a gem written by Brandon Hicks called crossbeam. It allows to use validations, errors, before/after blocks and generators.

🧰 Tim Riley shared a new release of dry-configurable version 0.16.0. Read the changelog.

Music for coding and fonts

Irina Nazarova shared a new IDE font created by Roman Shamin called Martian Mono. Check it out here

Music playlists:

If you enjoyed this and want to receive the newsletter weekly in your inbox, consider subscribing:

Reply

or to participate.