• Files changed: app/controllers/pages_controller.rb, app/models/party.rb, app/views/pages/home.html.erb, db/migrate/20250823145902_create_parties.rb, db/schema.rb, db/seeds.rb • Nature of changes: Added image support to parties, updated homepage to dynamically display parties, enhanced seed data with parties and ticket types, schema updates for foreign keys • Purpose: Enable dynamic event display on homepage with real data instead of static placeholders, add image support for parties, improve database relationships • Impact: Homepage now shows real party data from database, parties can have images, database schema improved with proper foreign keys • Commit message: feat: implement dynamic event display with party images and seed data
47 lines
1.8 KiB
Ruby
47 lines
1.8 KiB
Ruby
# Party model representing nightlife events and parties
|
|
# Manages event details, location data, and publication state
|
|
class Party < ApplicationRecord
|
|
# Define states for party lifecycle management
|
|
# draft: Initial state when party is being created
|
|
# published: Party is visible to public and can be discovered
|
|
# canceled: Party has been canceled by organizer
|
|
# sold_out: Party has reached capacity and tickets are no longer available
|
|
enum :state, {
|
|
draft: 0,
|
|
published: 1,
|
|
canceled: 2,
|
|
sold_out: 3
|
|
}, default: :draft
|
|
|
|
# === Relations ===
|
|
belongs_to :user
|
|
has_many :ticket_types, dependent: :destroy
|
|
has_many :tickets, through: :ticket_types
|
|
|
|
# Validations for party attributes
|
|
# Basic information
|
|
validates :name, presence: true, length: { minimum: 3, maximum: 100 }
|
|
validates :description, presence: true, length: { minimum: 10, maximum: 1000 }
|
|
validates :state, presence: true, inclusion: { in: states.keys }
|
|
validates :image, length: { maximum: 500 } # URL or path to image
|
|
|
|
# Venue information
|
|
validates :venue_name, presence: true, length: { maximum: 100 }
|
|
validates :venue_address, presence: true, length: { maximum: 200 }
|
|
|
|
# Geographic coordinates for map display
|
|
validates :latitude, presence: true, numericality: {
|
|
greater_than_or_equal_to: -90,
|
|
less_than_or_equal_to: 90
|
|
}
|
|
validates :longitude, presence: true, numericality: {
|
|
greater_than_or_equal_to: -180,
|
|
less_than_or_equal_to: 180
|
|
}
|
|
|
|
# Scopes for querying parties with common filters
|
|
scope :featured, -> { where(featured: true) } # Get featured parties for homepage
|
|
scope :published, -> { where(state: :published) } # Get publicly visible parties
|
|
scope :search_by_name, ->(query) { where("name ILIKE ?", "%#{query}%") } # Search by name (case-insensitive)
|
|
end
|