fix: Resolve tickets controller Event lookup issues

- Fix Event attribute name from starts_at to start_time in orders/new view
- Update TicketsController#set_event to use session[:event_id] as fallback when params[:id] is not available
- Remove duplicate Event.find call in tickets#create action
- Fix form submission path in tickets/new to use parameterless route
- Add debug logging to troubleshoot event ID resolution
- Update redirect paths to use proper route helpers

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kbe
2025-09-04 01:12:59 +02:00
parent ee4399aa46
commit 0f6d75b1e8
3 changed files with 21 additions and 9 deletions

View File

@@ -46,11 +46,9 @@ class TicketsController < ApplicationController
@cart_data = session[:pending_cart] || {}
if @cart_data.empty?
redirect_to event_path(params[:slug], params[:id]), alert: "Aucun billet sélectionné"
redirect_to event_path(@event.slug, @event), alert: "Aucun billet sélectionné"
return
end
@event = Event.includes(:ticket_types).find(params[:id])
success = false
ActiveRecord::Base.transaction do
@@ -89,12 +87,12 @@ class TicketsController < ApplicationController
session.delete(:pending_cart)
redirect_to checkout_order_path(@order)
else
redirect_to ticket_new_path(@event.slug, @event.id)
redirect_to ticket_new_path
end
rescue => e
error_message = e.message.present? ? e.message : "Erreur inconnue"
flash[:alert] = "Une erreur est survenue: #{error_message}"
redirect_to ticket_new_path(params[:slug], params[:id])
redirect_to ticket_new_path
end
# Redirect to order-based checkout
@@ -147,7 +145,21 @@ class TicketsController < ApplicationController
private
def set_event
@event = Event.includes(:ticket_types).find(params[:id])
event_id = params[:id] || session[:event_id]
Rails.logger.debug "TicketsController#set_event - params[:id]: #{params[:id].inspect}, session[:event_id]: #{session[:event_id].inspect}"
unless event_id
Rails.logger.error "TicketsController#set_event - No event ID found"
redirect_to events_path, alert: "Aucun événement spécifié"
return
end
@event = Event.includes(:ticket_types).find(event_id)
Rails.logger.debug "TicketsController#set_event - Found event: #{@event.id} - #{@event.name}"
rescue ActiveRecord::RecordNotFound
Rails.logger.error "TicketsController#set_event - Event not found with ID: #{event_id}"
redirect_to events_path, alert: "Événement non trouvé"
end
def ticket_params

View File

@@ -14,9 +14,9 @@
<div class="mb-6">
<h3 class="text-lg font-medium text-gray-800"><%= @event.name %></h3>
<p class="text-gray-600"><%= @event.venue_name %></p>
<% if @event.starts_at %>
<% if @event.start_time %>
<p class="text-sm text-gray-500">
<%= @event.starts_at.strftime("%d/%m/%Y à %H:%M") %>
<%= @event.start_time.strftime("%d/%m/%Y à %H:%M") %>
</p>
<% end %>
</div>

View File

@@ -98,7 +98,7 @@
les billets.</p>
</div>
<%= form_with url: ticket_create_path(@event.slug, @event), method: :post, local: true, class: "space-y-8" do |form| %>
<%= form_with url: ticket_create_path, method: :post, local: true, class: "space-y-8" do |form| %>
<% if @tickets_needing_names.any? %>
<div class="space-y-6">
<div class="flex items-center justify-center mb-2">