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/views/custom/partials/_chapter.html.erb | 4 ++-- app/views/nodes/show.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/views') diff --git a/app/views/custom/partials/_chapter.html.erb b/app/views/custom/partials/_chapter.html.erb index 47f3950c..5d47679e 100644 --- a/app/views/custom/partials/_chapter.html.erb +++ b/app/views/custom/partials/_chapter.html.erb @@ -1,7 +1,7 @@
- <% if page.assets.images.any? %> - <%= link_to_path image_tag(page.assets.images.first.upload.url(:thumb), :alt => ""), page.node.unique_name, class: "chapter_thumbnail" %> + <% if page.headline_asset %> + <%= link_to_path image_tag(page.headline_asset.upload.url(:thumb), :alt => ""), page.node.unique_name, class: "chapter_thumbnail" %> <% end %>

<%= link_to_path page.title, page.node.unique_name %>

diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index a7be3c6f..f2b4b154 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb @@ -254,7 +254,7 @@
<% if @page.assets.images.any? %> - <% headline_asset_id = @page.related_assets.find_by(headline: true)&.asset_id %> + <% headline_asset_id = @page.headline_asset&.id %>
Images
    -- cgit v1.3