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 | |
| 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')
| -rw-r--r-- | app/helpers/content_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/page.rb | 4 | ||||
| -rw-r--r-- | app/views/custom/partials/_chapter.html.erb | 4 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 2 |
4 files changed, 8 insertions, 4 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index b3c6bad..459d9e0 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -53,7 +53,7 @@ module ContentHelper | |||
| 53 | end | 53 | end |
| 54 | 54 | ||
| 55 | def headline_image | 55 | def headline_image |
| 56 | @headline_asset = @page.related_assets.find_by(headline: true)&.asset | 56 | @headline_asset = @page.headline_asset |
| 57 | render :partial => 'content/headline_image' if @headline_asset || @page.assets.images.any? | 57 | render :partial => 'content/headline_image' if @headline_asset || @page.assets.images.any? |
| 58 | end | 58 | end |
| 59 | 59 | ||
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 |
diff --git a/app/views/custom/partials/_chapter.html.erb b/app/views/custom/partials/_chapter.html.erb index 47f3950..5d47679 100644 --- a/app/views/custom/partials/_chapter.html.erb +++ b/app/views/custom/partials/_chapter.html.erb | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | <div class="article_partial chapter_partial" lang="<%= page.effective_lang %>"> | 1 | <div class="article_partial chapter_partial" lang="<%= page.effective_lang %>"> |
| 2 | <div class="chapter_partial_layout"> | 2 | <div class="chapter_partial_layout"> |
| 3 | <% if page.assets.images.any? %> | 3 | <% if page.headline_asset %> |
| 4 | <%= link_to_path image_tag(page.assets.images.first.upload.url(:thumb), :alt => ""), page.node.unique_name, class: "chapter_thumbnail" %> | 4 | <%= link_to_path image_tag(page.headline_asset.upload.url(:thumb), :alt => ""), page.node.unique_name, class: "chapter_thumbnail" %> |
| 5 | <% end %> | 5 | <% end %> |
| 6 | <div class="chapter_partial_content"> | 6 | <div class="chapter_partial_content"> |
| 7 | <h2 class="headline"><%= link_to_path page.title, page.node.unique_name %></h2> | 7 | <h2 class="headline"><%= link_to_path page.title, page.node.unique_name %></h2> |
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index a7be3c6..f2b4b15 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb | |||
| @@ -254,7 +254,7 @@ | |||
| 254 | </div> | 254 | </div> |
| 255 | 255 | ||
| 256 | <% if @page.assets.images.any? %> | 256 | <% if @page.assets.images.any? %> |
| 257 | <% headline_asset_id = @page.related_assets.find_by(headline: true)&.asset_id %> | 257 | <% headline_asset_id = @page.headline_asset&.id %> |
| 258 | <div class="node_description">Images</div> | 258 | <div class="node_description">Images</div> |
| 259 | <div class="node_content node_info_group"> | 259 | <div class="node_content node_info_group"> |
| 260 | <ul class="thumbnail_list"> | 260 | <ul class="thumbnail_list"> |
