Add TicketType model with validations and fix dropdown menu

- Create TicketType model with Party association and Ticket relationship
- Add comprehensive validations for name, description, pricing, and date ranges
- Generate migration for ticket_types table with all required fields
- Add Alpine.js import to fix dropdown menu functionality
- Update ticket model with validations for qr_code, price, and status
This commit is contained in:
kbe
2025-08-23 19:31:17 +02:00
parent ef9cfd6cdf
commit b5b5ca1cc0
10 changed files with 129 additions and 8 deletions

8
app/models/ticket.rb Normal file
View File

@@ -0,0 +1,8 @@
class Ticket < ApplicationRecord
# Validations
validates :qr_code, presence: true, uniqueness: true
validates :party_id, presence: true
validates :user_id, presence: true
validates :price_cents, presence: true, numericality: { greater_than: 0 }
validates :status, presence: true, inclusion: { in: %w[active used expired refunded] }
end

24
app/models/ticket_type.rb Normal file
View File

@@ -0,0 +1,24 @@
class TicketType < ApplicationRecord
# Associations
belongs_to :party
has_many :tickets
# Validations
validates :name, presence: true, length: { minimum: 3, maximum: 50 }
validates :description, presence: true, length: { minimum: 10, maximum: 500 }
validates :price_cents, presence: true, numericality: { greater_than: 0 }
validates :quantity, presence: true, numericality: { only_integer: true, greater_than: 0 }
validates :party_id, presence: true
validates :sale_start_at, presence: true
validates :sale_end_at, presence: true
validate :sale_end_after_start
validates :requires_id, inclusion: { in: [true, false] }
validates :minimum_age, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 120 }, allow_nil: true
private
def sale_end_after_start
return unless sale_start_at && sale_end_at
errors.add(:sale_end_at, "must be after sale start") if sale_end_at <= sale_start_at
end
end