diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-21 21:34:14 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-21 21:34:14 +0200 |
| commit | ec8329069d36cc6aa444c8a48b6b34a3e8f5c9d2 (patch) | |
| tree | 8a94a94984c0ff20cb3e6dcf12ee212fc98a9ae0 /app/models | |
| parent | 5b951f012e04e6ef97e4ef645d53bdf433a9eb7f (diff) | |
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.
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/page.rb | 4 |
1 files changed, 4 insertions, 0 deletions
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 | |||
| 292 | end | 292 | end |
| 293 | end | 293 | end |
| 294 | 294 | ||
| 295 | def headline_asset | ||
| 296 | related_assets.find_by(headline: true)&.asset | ||
| 297 | end | ||
| 298 | |||
| 295 | # Returns true if a page has translations where one of them is significantly | 299 | # Returns true if a page has translations where one of them is significantly |
| 296 | # older than the other. | 300 | # older than the other. |
| 297 | # Takes the I18n.default locale and a second :locale to test if the | 301 | # Takes the I18n.default locale and a second :locale to test if the |
