Files
aperonight/app/controllers/pages_controller.rb
2025-09-10 20:49:06 +02:00

60 lines
2.5 KiB
Ruby
Executable File

# Controller for static pages and user dashboard
# Handles basic page rendering and user-specific content
class PagesController < ApplicationController
before_action :authenticate_user!, only: [ :dashboard ]
# Homepage showing featured events as landing page
#
# Display homepage with featured events and site metrics for all users
def home
# Featured events for the main grid (6-9 events like Shotgun)
@featured_events = Event.published.featured.includes(:ticket_types).limit(9)
# If no featured events, show latest published events
if @featured_events.empty?
@featured_events = Event.published.includes(:ticket_types).order(created_at: :desc).limit(9)
end
# Upcoming events for additional content
@upcoming_events = Event.published.upcoming.limit(6)
# Site metrics for landing page (with realistic fake data for demo)
@total_events = [Event.published.count, 50].max # At least 50 events for demo
@total_users = [User.count, 2500].max # At least 2500 users for demo
@events_this_month = [Event.published.where(created_at: 1.month.ago..Time.current).count, 12].max # At least 12 this month
@active_cities = 5 # Fixed number for demo
end
# User dashboard showing personalized content
# Accessible only to authenticated users
def dashboard
# User's orders with associated data
@user_orders = current_user.orders.includes(:event, tickets: :ticket_type)
.where(status: [ "paid", "completed" ])
.order(created_at: :desc)
.limit(10)
# Draft orders that can be retried
@draft_orders = current_user.orders.includes(tickets: [ :ticket_type, :event ])
.can_retry_payment
.order(:expires_at)
# Simplified upcoming events preview - only show if user has orders
if @user_orders.any?
ordered_event_ids = @user_orders.map(&:event).map(&:id)
@upcoming_preview_events = Event.published
.upcoming
.where.not(id: ordered_event_ids)
.order(start_time: :asc)
.limit(6)
else
@upcoming_preview_events = []
end
end
# Events page showing all published events with pagination
def events
@events = Event.published.order(created_at: :desc).page(params[:page])
end
end