Skip to main content
Published in Engineering Insights

Gnarly Learnings from February

Gnarly Learnings from February
Table of contents
  1. Rails 6 deprecates where.not as NOR & Rails 6.1 as NAND
  2. Rails 6.1 adds query method missing to find orphan records
  3. Modern CSS with Tailwind
  4. There's No Such Thing as a Free Gem
  5. React State Batch Update
  6. Why Pry is one of the most important tools a junior Rubyist can learn
  7. The career-changing art of reading the docs
  8. Rails' hidden type system
  9. Contributors

We love reading, watching, and listening to constantly update our skills and learn new perspectives. Here are some of the exciting pieces we learned from this month.

Rails 6 deprecates where.not as NOR & Rails 6.1 as NAND#

ActiveRecord queries are often a large part of the day in the life of a Rails developer. Recently, we reached for them in order to select some records by leveraging where.not with multiple attributes. However, when we ran the specs we received a warning stating that this implementation has been depreciated due to unapparent behavior related to the conditional logic involved. Previously, logical NOR was used when applying the clause with multiple attributes, but as of Rails 6.1 logical NAND will be used instead.

What does this mean for you? Well, if you want to select for multiple attributes you can either use NAND logic such as where("foo != 'Foo' OR bar != 'Bar'") or you can chain separate where.not statements for each attribute.

Rails 6.1 adds query method missing to find orphan records#

Some of our work involves large amounts of interconnected data. When a record is "orphaned", meaning it loses its "parent" record, this new method gives us an expressive API for querying those orphaned records.

Modern CSS with Tailwind#

This book is a great introduction to the Tailwind utility CSS framework, as well as a valuable reference guide if you're already familiar.

There's No Such Thing as a Free Gem#

Come for the promise of how to build an OAuth flow; stay for the discussion on evaluating the impact of a build vs. buy vs. borrow decision. This reinforced a lot of the conclusions I came to when I asked at RailsConf 2019: I know I can, but should I?

React State Batch Update#

Modern react components leverage functional patterns to remain flexible, while still tracking and making changes on state within themselves. We learned that react helps us out by batching these hook-based state update functions so that we do not render unecessarily, and always group these changes so that they are changed within a single re-render.

Why Pry is one of the most important tools a junior Rubyist can learn#

We ❤️ using Pry. If this article convinces you to dig into it, we have some additional tips available as well.

The career-changing art of reading the docs#

Poring through documentation in the heat of the moment can be a necessity. Pre-emptively consuming documentation requires time (and privilege), but can help you (and others) out of jams, either by being able to find the information required, or recall it without the docs.

Rails' hidden type system#

Rails's Attributes API is a great abstraction for helping Rails' internals, but also is very helpful for coercing types out of input for non-ActiveRecord classes, for example from controller parameters.

Contributors#

Frequently asked questions

How can I query multiple attributes with where.not?

The post gives two approaches: use NAND logic, such as where("foo != 'Foo' OR bar != 'Bar'"), or chain separate where.not statements for each attribute.

Why does React batch state updates?

React batches hook-based state update functions to avoid unnecessary rendering. It groups those changes within a single re-render.

Why read documentation before I need it?

It takes time, but it can help you and others out of a jam. You may know where to find the needed information or remember it without reopening the docs.

Stay In The Loop

Never miss an update. Get the latest blogs, webinars, and expert insights straight to your inbox from The Gnar.