From b33552f6b1c287cb0d1b764f55b24d103f06464b Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 25 Mar 2025 17:15:19 +0800 Subject: [PATCH] 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. --- app/views/home/index.html.erb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 3a05bf4..d5dc8a9 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -3,7 +3,11 @@
<% if @latest_arts.first&.image&.attached? %>
- <%= 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 %>
<% end %>