From ec8329069d36cc6aa444c8a48b6b34a3e8f5c9d2 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Tue, 21 Jul 2026 21:34:14 +0200 Subject: Extract Page#headline_asset The same related_assets.find_by(headline: true) query was written by hand in three places -- content_helper, nodes#show, and the chapter teaser partial (which was still using assets.first, the old position-based rule, until now). Collapsed to one method, one query. --- app/models/page.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/models') diff --git a/app/models/page.rb b/app/models/page.rb index c1498fc..817e3bd 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -292,6 +292,10 @@ class Page < ApplicationRecord end end + def headline_asset + related_assets.find_by(headline: true)&.asset + end + # Returns true if a page has translations where one of them is significantly # older than the other. # Takes the I18n.default locale and a second :locale to test if the -- cgit v1.3