Fix ticket PDF generation by passing data directly to print_qr_code

This commit is contained in:
kbe
2025-09-05 23:03:50 +02:00
parent a984243fe2
commit 7009245ab0
2 changed files with 11 additions and 5 deletions

View File

@@ -3,7 +3,7 @@
# This controller now primarily handles legacy redirects and backward compatibility # This controller now primarily handles legacy redirects and backward compatibility
# Most ticket creation functionality has been moved to OrdersController # Most ticket creation functionality has been moved to OrdersController
class TicketsController < ApplicationController class TicketsController < ApplicationController
before_action :authenticate_user!, only: [ :payment_success, :payment_cancel ] before_action :authenticate_user!, only: [ :payment_success, :payment_cancel, :show, :download_ticket ]
before_action :set_event, only: [ :checkout, :retry_payment ] before_action :set_event, only: [ :checkout, :retry_payment ]
@@ -49,7 +49,10 @@ class TicketsController < ApplicationController
end end
def show def show
@ticket = current_user.orders.joins(:tickets).find(params[:ticket_id]) @ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by(
tickets: { id: params[:ticket_id] },
orders: { user_id: current_user.id }
)
@event = @ticket.event @event = @ticket.event
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
redirect_to dashboard_path, alert: "Billet non trouvé" redirect_to dashboard_path, alert: "Billet non trouvé"
@@ -58,7 +61,10 @@ class TicketsController < ApplicationController
# Download PDF ticket - only accessible by ticket owner # Download PDF ticket - only accessible by ticket owner
def download_ticket def download_ticket
# Find ticket and ensure it belongs to current user # Find ticket and ensure it belongs to current user
@ticket = current_user.orders.joins(:tickets).find_by(tickets: { id: params[:ticket_id] }) @ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by(
tickets: { id: params[:ticket_id] },
orders: { user_id: current_user.id }
)
if @ticket.nil? if @ticket.nil?
redirect_to dashboard_path, alert: "Billet non trouvé ou vous n'avez pas l'autorisation d'accéder à ce billet" redirect_to dashboard_path, alert: "Billet non trouvé ou vous n'avez pas l'autorisation d'accéder à ce billet"

View File

@@ -91,8 +91,8 @@ class TicketPdfGenerator
raise "QR code data is empty or invalid" raise "QR code data is empty or invalid"
end end
qrcode = RQRCode::QRCode.new(qr_code_data) # Generate QR code - prawn-qrcode expects the data string directly
pdf.print_qr_code(qrcode, extent: 120, align: :center) pdf.print_qr_code(qr_code_data, extent: 120, align: :center)
pdf.move_down 15 pdf.move_down 15