fix: Update views and controllers for event image display

Update all event-related view templates and controllers to properly handle and display event images throughout the application.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kbe
2025-10-01 08:12:47 +02:00
parent 6be8b95ed3
commit 20dcee0a5b
10 changed files with 66 additions and 26 deletions

View File

@@ -27,6 +27,7 @@ class Event < ApplicationRecord
# === Callbacks ===
before_validation :geocode_address, if: :should_geocode_address?
before_update :handle_image_replacement, if: :image_attached?
# Validations for Event attributes
# Basic information
@@ -61,8 +62,26 @@ class Event < ApplicationRecord
# === Instance Methods ===
# Get image URL prioritizing old image field if it exists
def display_image_url
# First check if old image field exists and has a value
return self[:image] if self[:image].present?
# Fall back to attached image
return nil unless image.attached?
# Return the URL for the attached image
Rails.application.routes.url_helpers.rails_blob_url(image, only_path: true)
end
# Get image variants for different display sizes
def event_image_variant(size = :medium)
# For old image field, return the URL directly
return self[:image] if self[:image].present?
# For attached images, process variants
return nil unless image.attached?
case size
when :large
image.variant(resize_to_limit: [1200, 630])
@@ -75,6 +94,11 @@ class Event < ApplicationRecord
end
end
# Check if event has any image (old field or attached)
def has_image?
self[:image].present? || image.attached?
end
# Check if coordinates were successfully geocoded or are fallback coordinates
def geocoding_successful?
coordinates_look_valid?
@@ -169,6 +193,19 @@ class Event < ApplicationRecord
private
# Check if image is attached for the callback
def image_attached?
image.attached?
end
# Handle image replacement when a new image is uploaded
def handle_image_replacement
# Clear the old image field if a new image is being attached
if image.attached?
self[:image] = nil
end
end
# Determine if we should perform server-side geocoding
def should_geocode_address?
# Don't geocode if address is blank