fix: add error handling for image loading

- Implemented error handling for image loading to prevent application
  crashes when an image fails to load.
- Added logging to capture the error message when an image cannot be
  displayed.

This change improves the reliability of the image display feature on
the home page, ensuring that users are not met with a broken layout
if an image fails to load.
This commit is contained in:
songtianlun 2025-03-25 17:15:19 +08:00
parent 6b3d290c4e
commit b33552f6b1

View File

@ -3,7 +3,11 @@
<section class="h-screen-90 relative overflow-hidden">
<% if @latest_arts.first&.image&.attached? %>
<div class="absolute inset-0">
<%= image_tag @latest_arts&.first&.webp_image&.processed, class: "w-full h-full object-cover" %>
<% begin %>
<%= image_tag @latest_arts&.first&.webp_image&.processed, class: "w-full h-full object-cover" %>
<% rescue StandardError => e %>
<% Rails.logger.error("图片加载失败: #{e.message}") if defined?(Rails) %>
<% end %>
<div class="absolute inset-0 bg-gradient-to-r from-base-100/90 to-base-100/50"></div>
</div>
<% end %>