fix: Add slug column to parties table and update seed data

- Added slug column to parties table via migration
- Updated seed data to properly assign slug values to Party records
- Fixed NoMethodError when assigning slug attribute in seed file

This resolves the ActiveModel::UnknownAttributeError that occurred
when trying to set the slug attribute on Party model instances.
This commit is contained in:
Kevin BATAILLE
2025-08-26 02:27:18 +02:00
parent 6385c39c10
commit a0f008bbd4
14 changed files with 364 additions and 80 deletions

View File

@@ -1,4 +1,4 @@
class EventsController < ApplicationController
class PartiesController < ApplicationController
# Display all events
def index
@parties = Party.includes(:user).upcoming.page(params[:page]).per(12)
@@ -6,5 +6,6 @@ class EventsController < ApplicationController
# Display desired event
def show
@party = Party.find(params[:id])
end
end

View File

@@ -21,6 +21,7 @@ class Party < ApplicationRecord
# Validations for party attributes
# Basic information
validates :name, presence: true, length: { minimum: 3, maximum: 100 }
validates :slug, 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
@@ -43,7 +44,8 @@ class Party < ApplicationRecord
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)
# Scope for published parties ordered by start time
scope :upcoming, -> { published.where("start_time >= ?", Time.current).order(start_time: :asc) }
end

View File

@@ -12,7 +12,7 @@
<!-- Navigation Links -->
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex items-center">
<%= link_to "Soirées et afterworks", events_path, class: "text-white hover:text-purple-200 px-3 py-2 rounded-md text-sm font-medium transition-colors duration-200" %>
<%= link_to "Soirées et afterworks", parties_path, class: "text-white hover:text-purple-200 px-3 py-2 rounded-md text-sm font-medium transition-colors duration-200" %>
<%= link_to "Concerts", "#", class: "text-white hover:text-purple-200 px-3 py-2 rounded-md text-sm font-medium transition-colors duration-200" %>
</div>
</div>

View File

@@ -167,9 +167,9 @@
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<% @parties.each do |party| %>
<div class="bg-white border border-neutral-200 rounded-2xl overflow-hidden hover:transform hover:scale-105 transition-all duration-300 shadow-lg">
<div class="h-56 bg-gradient-to-br from-purple-500 via-pink-500 to-red-500 relative"
style="background-image: url('<%= party.image || "https://images.unsplash.com/photo-1506157786151-b84b9d3d78d8?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80" %>');
background-size: cover;
<div class="h-56 bg-gradient-to-br from-purple-500 via-pink-500 to-red-500 relative"
style="background-image: url('<%= party.image || "https://images.unsplash.com/photo-1506157786151-b84b9d3d78d8?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80" %>');
background-size: cover;
background-position: center;">
<div class="absolute top-4 right-4 bg-white bg-opacity-90 text-neutral-900 px-3 py-1 rounded-full text-sm font-medium">
<%= party.venue_name.split(' ').first %>
@@ -184,14 +184,14 @@
</div>
<p class="text-neutral-600 mb-2"><%= party.venue_name %>, <%= party.venue_address.split(',').first %></p>
<p class="text-neutral-700 mb-4"><%= I18n.l(party.start_time, format: "%A %Hh") if party.start_time %> • <%= party.description.split('.').first %></p>
<%= link_to "Réserver ma place", "#", class: "w-full bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700 text-white font-semibold py-3 rounded-lg transition-all duration-300 text-center block" %>
<%= link_to "Voir les détails", party_path(party.slug, party), class: "w-full bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700 text-white font-semibold py-3 rounded-lg transition-all duration-300 text-center block" %>
</div>
</div>
<% end %>
</div>
<div class="text-center mt-12">
<%= link_to "Voir tous les événements →", "#", class: "text-purple-600 hover:text-purple-700 text-lg font-medium transition-all duration-300 border-b-2 border-purple-600 hover:border-purple-700" %>
<%= link_to "Voir tous les événements →", parties_path, class: "text-purple-600 hover:text-purple-700 text-lg font-medium transition-all duration-300 border-b-2 border-purple-600 hover:border-purple-700" %>
</div>
</div>
</section>

View File

@@ -0,0 +1,37 @@
<div class="container mt-4">
<div class="row">
<div class="col-md-8">
<h1><%= @party.name %></h1>
<% if @party.image.present? %>
<%= image_tag @party.image, class: "img-fluid rounded mb-3" %>
<% end %>
<p><%= @party.description %></p>
<div class="card mb-3">
<div class="card-body">
<h5 class="card-title">Event Details</h5>
<p class="card-text">
<strong>Venue:</strong> <%= @party.venue_name %><br>
<strong>Address:</strong> <%= @party.venue_address %><br>
<strong>Start Time:</strong> <%= @party.start_time.strftime("%B %d, %Y at %I:%M %p") %><br>
<strong>End Time:</strong> <%= @party.end_time.strftime("%B %d, %Y at %I:%M %p") %>
</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Ticket Information</h5>
<p class="card-text">
<!-- Ticket types would go here -->
<a href="#" class="btn btn-primary">Get Tickets</a>
</p>
</div>
</div>
</div>
</div>
</div>