Files
aperonight/app/controllers/pages_controller.rb

43 lines
1.8 KiB
Ruby
Executable File

# Controller for static pages and user dashboard
# Handles basic page rendering and user-specific content
class PagesController < ApplicationController
# Skip authentication for public pages
# skip_before_action :authenticate_user!, only: [ :home ]
before_action :authenticate_user!, only: [ :dashboard ]
# Homepage showing featured events
def home
@events = Event.published.featured.limit(3)
if user_signed_in?
return redirect_to(dashboard_path)
end
end
# User dashboard showing personalized content
# Accessible only to authenticated users
def dashboard
# Metrics for dashboard cards
@booked_events = current_user.tickets.joins(:ticket_type, :event).where(events: { state: :published }).count
@events_today = Event.published.where("DATE(start_time) = ?", Date.current).count
@events_tomorrow = Event.published.where("DATE(start_time) = ?", Date.current + 1).count
@upcoming_events = Event.published.upcoming.count
# User's booked events
@user_booked_events = Event.joins(ticket_types: :tickets)
.where(tickets: { user: current_user, status: 'active' })
.distinct
.limit(5)
# Events sections
@today_events = Event.published.where("DATE(start_time) = ?", Date.current).order(start_time: :asc)
@tomorrow_events = Event.published.where("DATE(start_time) = ?", Date.current + 1).order(start_time: :asc)
@other_events = Event.published.upcoming.where.not("DATE(start_time) IN (?)", [Date.current, Date.current + 1]).order(start_time: :asc).page(params[:page])
end
# Events page showing all published events with pagination
def events
@events = Event.published.order(created_at: :desc).page(params[:page])
end
end