Skip to content

Commit

Permalink
ブログのサムネイルが最新記事に表示されるように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrimprin committed May 26, 2024
1 parent 2495e28 commit c490258
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Article < ApplicationRecord
paginates_per 24
acts_as_taggable

def prepared_thumbnail_url
def prepared_thumbnail_url(thumbnail_size = THUMBNAIL_SIZE)
if thumbnail.attached?
thumbnail.variant(resize_to_limit: THUMBNAIL_SIZE).processed.url
thumbnail.variant(resize_to_limit: thumbnail_size).processed.url
else
image_url('/ogp/blank.svg')
end
Expand Down
8 changes: 5 additions & 3 deletions app/views/articles/_recent_articles.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
= link_to recent_article, class: 'card-list-item__inner' do
.card-list-item__thumbnail
.card-list-item__thumbnail-inner
- if recent_article.thumbnail.attached?
= image_tag recent_article.thumbnail.variant(resize_to_limit: [200, 105]).processed.url, \
- if recent_article.prepared_thumbnail?
= image_tag recent_article.prepared_thumbnail_url([200, 105]), \
class: 'card-list-item__thumbnail-image', \
alt: "ブログ記事「#{recent_article.title}」のアイキャッチ画像"
- else
= image_tag 'work-blank.svg', class: 'card-list-item__thumbnail-image', alt: 'ブログ記事のブランクアイキャッチ画像'
= image_tag recent_article.selected_thumbnail_url, \
class: 'card-list-item__thumbnail-image', \
alt: "ブログ記事「#{recent_article.title}」のアイキャッチ画像"
.card-list-item__rows
.card-list-item__row
.card-list-item-title
Expand Down

0 comments on commit c490258

Please sign in to comment.