560 blogs tracked4,950 posts indexed

#ruby-on-rails

7 posts · 3 companies · newest first

1

We Ran Out of TCP Ports at 1:30 AM — the Crack Was tcp_tw_reuse=0 (opens on the source site)

A neighbor’s bulk job drained every ephemeral port on a shared box. Twice. Here’s the one kernel setting that would have stopped it — and the architecture that makes it a non-issue.At 1:38 AM, one of our background-job services started failing. Scheduled jobs — the nudges and reminders we send users overnight — began throwing an error most engineers rarely see:Errno::EADDRNOTAVAIL — Cannot assign requested addressNot “connection refused.” Not “timeout.” Cannot assign requested address. The machine wasn’t saying the other end was down. It was saying it had run out of addresses to call…

tcpproduction-issueexcerpt only · body stays at the source
From the web
3

Testing Readonly Models (opens on the source site)

I was working with a readonly model in Rails the other day and ran into an issue whilst testing it. Here's what I ran into and the solution I came up with. Readonly models are a great way to signal that, well, you should only ever read them, not write them. Maybe you have some external system that connects to the database for writes, or maybe your Rails app connects to some data warehouse for some queries or reports. It's can be useful to have a safeguard to prevent accidental errant writes. It's actually really simple to make a model readonly, you just need to override the readonly? method:…

testingruby-on-railsexcerpt only · body stays at the source
From the web
4

Naming Things Is Hard (opens on the source site)

Choosing good names for objects and methods in code is one of the toughest things to do as a software engineer. It comes with the great and invisible reward of simplicity – second only to having less code in the first place, having code that’s easy to reason with makes extending it and debugging it in […]

developmentgeneralexcerpt only · body stays at the source
From the web
5

Persisting nested form attribute indexes through Turbo updates (opens on the source site)

Introduction We recently encountered an interesting problem when using Turbo Streams to update part of a complex nested form in FreeAgent’s main Ruby on Rails web application. For those unfamiliar, nested forms allow a user to enter data relating to both a main parent object and its associated objects. This could be, for example, a […]

uncategorizedruby-on-railsexcerpt only · body stays at the source
From the web
6

Speed Up Your Rails App by Squashing N+1 Queries (opens on the source site)

N+1 queries are one of the most common performance killers in Rails apps, but also one of the easiest to fix. In this post, we'll see how a single line of code can reduce 1,101 database queries down to 3. N+1s occur in rails when you have associated ActiveRecord models, and iterate over one model while accessing fields on the associated records. This might be easier to explain with an example. Let's say you have the following ActiveRecord models: class Author ApplicationRecord has_many :posts end class Post ApplicationRecord belongs_to :author has_many :tags end class Tag ApplicationRecord…

activerecordperformanceexcerpt only · body stays at the source
From the web
7 shown

Privacy choices

Reading never requires analytics. These choices last 90 days on this browser.

Essential sign-in and security storage always stays on. Read the privacy notice.