diff --git a/app/models/event.rb b/app/models/event.rb index b0f56fd..4f65a49 100755 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -31,6 +31,7 @@ class Event < ApplicationRecord # === Callbacks === before_validation :generate_slug, if: :should_generate_slug? before_validation :geocode_address, if: :should_geocode_address? + before_validation :handle_image_url, if: :should_handle_image_url? before_update :handle_image_replacement, if: :image_attached? # Validations for Event attributes @@ -151,6 +152,9 @@ class Event < ApplicationRecord # For old image field, return the URL directly return self[:image] if self[:image].present? + # For virtual image_url attribute, return the URL directly + return image_url if image_url.present? + # For attached images, process variants return nil unless image.attached? @@ -275,9 +279,10 @@ class Event < ApplicationRecord end end - # Validate image URL format + # Validate image URL format - relaxed for development def image_url_format return unless image_url.present? + return if Rails.env.development? # Skip validation in development unless image_url.match?(/\Ahttps?:\/\/.+\.(jpg|jpeg|png|gif|webp)(\?.*)?\z/i) errors.add(:image_url, "doit être une URL valide vers une image (JPG, PNG, GIF, WebP)") @@ -299,6 +304,19 @@ class Event < ApplicationRecord end end + # Determine if we should handle image_url + def should_handle_image_url? + image_url.present? && new_record? + end + + # Handle image_url by storing it in the legacy image field + def handle_image_url + # Store the image_url in the legacy image field for backward compatibility + if image_url.present? + self[:image] = image_url + end + end + # Determine if we should perform server-side geocoding def should_geocode_address? # Don't geocode if address is blank diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb index e04755a..a4aa059 100755 --- a/app/views/events/show.html.erb +++ b/app/views/events/show.html.erb @@ -12,11 +12,7 @@ <% if @event.has_image? %>
- <% if @event.image.attached? %> - <%= image_tag @event.event_image_variant(:large), class: "w-full h-full object-cover" %> - <% else %> - <%= image_tag @event.image_url, class: "w-full h-full object-cover", alt: @event.name %> - <% end %> + <%= image_tag @event.event_image_variant(:large), class: "w-full h-full object-cover", alt: @event.name %>
diff --git a/db/schema.rb b/db/schema.rb index 7e08fec..23e160d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -56,7 +56,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_29_222616) do t.boolean "allow_booking_during_event", default: false, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "image_url" t.index ["featured"], name: "index_events_on_featured" t.index ["latitude", "longitude"], name: "index_events_on_latitude_and_longitude" t.index ["state"], name: "index_events_on_state" @@ -159,7 +158,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_29_222616) do t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end - add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "order_promotion_codes", "orders" add_foreign_key "order_promotion_codes", "promotion_codes" diff --git a/db/seeds.rb b/db/seeds.rb index 6975d87..9bff890 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -156,7 +156,7 @@ belle_epoque_event.update!(start_time: 3.days.from_now, end_time: 3.days.from_no # Create ticket types for "La belle époque" event -belle_epoque_event = Event.find_by!(slug: "la-belle-epoque-par-sisley-events") +belle_epoque_event = Event.find_by!(slug: "la-belle-epoque-par-sisley-events-le-patio-rooftop-montreuil") TicketType.find_or_create_by!(event: belle_epoque_event, name: "Free invitation valid before 7 p.m.") do |tt| tt.description = "Free invitation ticket valid before 7 p.m. for La Belle Époque"