feat: improve seo urls?

This commit is contained in:
kbe
2025-09-06 01:44:48 +02:00
parent fa99a167a5
commit 5105964b39
22 changed files with 702 additions and 367 deletions

View File

@@ -27,10 +27,33 @@ class EventsController < ApplicationController
private
# Find and set the current event with eager-loaded associations
#
# Supports both old slug-only format and new SEO-friendly year/month/slug format
# Loads event with ticket types to avoid N+1 queries
# Raises ActiveRecord::RecordNotFound if event doesn't exist
def set_event
@event = Event.includes(:ticket_types).find(params[:id])
if params[:year] && params[:month]
# New SEO-friendly format: /events/2024/07/summer-party
year = params[:year].to_i
month = params[:month].to_i
start_of_month = Date.new(year, month, 1).beginning_of_month
end_of_month = start_of_month.end_of_month
@event = Event.includes(:ticket_types)
.where(slug: params[:slug])
.where(start_time: start_of_month..end_of_month)
.first!
else
# Legacy format: /events/summer-party (for backward compatibility)
@event = Event.includes(:ticket_types).find_by!(slug: params[:slug])
end
rescue ActiveRecord::RecordNotFound
redirect_to events_path, alert: "Événement non trouvé"
end
# Generate SEO-friendly path for an event
def seo_event_path(event)
year = event.start_time.year
month = format("%02d", event.start_time.month)
event_path(year: year, month: month, slug: event.slug)
end
helper_method :seo_event_path
end