diff --git a/app/models/event.rb b/app/models/event.rb index d01941c..35bb3a2 100755 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -96,6 +96,12 @@ class Event < ApplicationRecord Time.current >= end_time end + # Check if booking is allowed during the event + # This is a simple attribute reader that defaults to false if nil + def allow_booking_during_event? + !!allow_booking_during_event + end + private # Determine if we should perform server-side geocoding diff --git a/app/models/ticket_type.rb b/app/models/ticket_type.rb index 2bca6cd..f06cfd5 100755 --- a/app/models/ticket_type.rb +++ b/app/models/ticket_type.rb @@ -1,7 +1,7 @@ class TicketType < ApplicationRecord # Associations belongs_to :event - has_many :tickets, dependent: :destroy + has_many :tickets, dependent: :destroy # Cannot delete ticket types if already tickets sold # Validations validates :name, presence: true, length: { minimum: 3, maximum: 50 } @@ -80,6 +80,10 @@ class TicketType < ApplicationRecord def sale_times_within_event_period return unless event&.start_time && sale_end_at - errors.add(:sale_end_at, "cannot be after the event starts") if sale_end_at > event.start_time + + # Only enforce this restriction if booking during event is not allowed + unless event.allow_booking_during_event? + errors.add(:sale_end_at, "cannot be after the event starts") if sale_end_at > event.start_time + end end end