feat: implement dynamic event display with party images and seed data

• 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
This commit is contained in:
kbe
2025-08-25 03:39:20 +02:00
parent 632055c44d
commit 6fbd24e36e
8 changed files with 798 additions and 68 deletions

View File

@@ -2,6 +2,7 @@ class CreateParties < ActiveRecord::Migration[8.0]
def change
create_table :parties do |t|
t.string :name, null: false
t.string :image, null: true
t.text :description, null: false
t.integer :state, default: 0, null: false
t.string :venue_name, null: false

16
db/schema.rb generated
View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_08_23_171354) do
ActiveRecord::Schema[8.0].define(version: 2025_08_25_012827) do
create_table "parties", force: :cascade do |t|
t.string "name", null: false
t.text "description", null: false
@@ -22,9 +22,10 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_23_171354) do
t.decimal "latitude", precision: 10, scale: 6, null: false
t.decimal "longitude", precision: 10, scale: 6, null: false
t.boolean "featured", default: false, null: false
t.integer "user_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "user_id", null: false
t.string "image"
t.index ["featured"], name: "index_parties_on_featured"
t.index ["latitude", "longitude"], name: "index_parties_on_latitude_and_longitude"
t.index ["state"], name: "index_parties_on_state"
@@ -32,6 +33,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_23_171354) do
end
create_table "ticket_types", force: :cascade do |t|
t.bigint "party_id", null: false
t.string "name"
t.text "description"
t.integer "price_cents"
@@ -40,7 +42,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_23_171354) do
t.datetime "sale_end_at"
t.boolean "requires_id"
t.integer "minimum_age"
t.integer "party_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["party_id"], name: "index_ticket_types_on_party_id"
@@ -52,8 +53,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_23_171354) do
t.string "qr_code"
t.integer "price_cents"
t.string "status", default: "active"
t.integer "user_id", null: false
t.integer "ticket_type_id", null: false
t.bigint "user_id", null: false
t.bigint "ticket_type_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["qr_code"], name: "index_tickets_on_qr_code", unique: true
@@ -72,4 +73,9 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_23_171354) do
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key "parties", "users"
add_foreign_key "ticket_types", "parties"
add_foreign_key "tickets", "ticket_types"
add_foreign_key "tickets", "users"
end

View File

@@ -7,3 +7,103 @@
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end
# Create admin user for development
admin_user = User.find_or_create_by!(email: 'admin@example.com') do |u|
u.password = 'password'
u.password_confirmation = 'password'
end
# Create regular users for development
users = User.where.not(email: 'admin@example.com').limit(5)
missing_users_count = 5 - users.count
missing_users_count.times do |i|
User.find_or_create_by!(email: "user#{i + 1}@example.com") do |u|
u.password = 'password'
u.password_confirmation = 'password'
end
end
# Reload all users after creation
users = User.all.to_a
# Create sample parties
parties_data = [
{
name: "Summer Beach Party",
description: "Join us for an amazing night at the beach with music, dancing, and cocktails.",
venue_name: "Sunset Beach Resort",
venue_address: "123 Ocean Drive, Miami, FL",
latitude: 25.7617,
longitude: -80.1918,
start_time: 1.day.from_now,
end_time: 1.day.from_now + 6.hours,
featured: true,
image: "https://images.unsplash.com/photo-1506157786151-b84b9d3d78d8?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80",
user: users.first
},
{
name: "Rooftop Jazz Night",
description: "Experience smooth jazz under the stars at our exclusive rooftop venue.",
venue_name: "Skyline Rooftop Bar",
venue_address: "456 Downtown Ave, New York, NY",
latitude: 40.7128,
longitude: -74.0060,
start_time: 3.days.from_now,
end_time: 3.days.from_now + 4.hours,
featured: true,
image: "https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80",
user: users.second
},
{
name: "Warehouse Electronic Festival",
description: "A night of electronic music and dancing in an industrial warehouse setting.",
venue_name: "Downtown Warehouse",
venue_address: "789 Industrial Blvd, Los Angeles, CA",
latitude: 34.0522,
longitude: -118.2437,
start_time: 1.week.from_now,
end_time: 1.week.from_now + 8.hours,
featured: false,
image: "https://images.unsplash.com/photo-1470225620780-dba8ba36b745?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80",
user: users.third
}
]
parties = []
parties_data.each do |party_data|
user = party_data.delete(:user)
party = Party.find_or_create_by!(name: party_data[:name]) do |p|
p.assign_attributes(party_data)
p.user = user
p.state = :published
end
parties << party
end
# Create ticket types for each party
parties.each_with_index do |party, index|
# General Admission ticket type
TicketType.find_or_create_by!(party: party, name: "General Admission") do |tt|
tt.description = "General admission ticket for #{party.name}"
tt.price_cents = 2500 # $25.00
tt.quantity = 100
tt.sale_start_at = 1.month.ago
tt.sale_end_at = party.start_time - 1.hour
tt.requires_id = false
tt.minimum_age = 18
end
# VIP ticket type
TicketType.find_or_create_by!(party: party, name: "VIP") do |tt|
tt.description = "VIP access ticket for #{party.name} with premium benefits"
tt.price_cents = 7500 # $75.00
tt.quantity = 20
tt.sale_start_at = 1.month.ago
tt.sale_end_at = party.start_time - 1.hour
tt.requires_id = true
tt.minimum_age = 21
end
end
puts "Created #{User.count} users, #{Party.count} parties, and #{TicketType.count} ticket types"