added parties
This commit is contained in:
70
app/controllers/parties_controller.rb
Normal file
70
app/controllers/parties_controller.rb
Normal file
@ -0,0 +1,70 @@
|
||||
class PartiesController < ApplicationController
|
||||
before_action :set_party, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /parties or /parties.json
|
||||
def index
|
||||
@parties = Party.all
|
||||
end
|
||||
|
||||
# GET /parties/1 or /parties/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /parties/new
|
||||
def new
|
||||
@party = Party.new
|
||||
end
|
||||
|
||||
# GET /parties/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /parties or /parties.json
|
||||
def create
|
||||
@party = Party.new(party_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @party.save
|
||||
format.html { redirect_to @party, notice: "Party was successfully created." }
|
||||
format.json { render :show, status: :created, location: @party }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @party.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /parties/1 or /parties/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @party.update(party_params)
|
||||
format.html { redirect_to @party, notice: "Party was successfully updated.", status: :see_other }
|
||||
format.json { render :show, status: :ok, location: @party }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
format.json { render json: @party.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /parties/1 or /parties/1.json
|
||||
def destroy
|
||||
@party.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to parties_path, notice: "Party was successfully destroyed.", status: :see_other }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_party
|
||||
@party = Party.find(params.expect(:id))
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def party_params
|
||||
params.expect(party: [ :title, :location, :start_date, :start_time, :status ])
|
||||
end
|
||||
end
|
||||
2
app/helpers/parties_helper.rb
Normal file
2
app/helpers/parties_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module PartiesHelper
|
||||
end
|
||||
4
app/models/attendent.rb
Normal file
4
app/models/attendent.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class Attendent < ApplicationRecord
|
||||
belongs_to :parties
|
||||
belongs_to :friends
|
||||
end
|
||||
2
app/models/party.rb
Normal file
2
app/models/party.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class Party < ApplicationRecord
|
||||
end
|
||||
@ -5,6 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
|
||||
@ -29,6 +30,7 @@
|
||||
<li><%= link_to "Leistungen", pages_path(:leistungen) %></li>
|
||||
<li><%= link_to "Anfahrt", pages_path(:anfahrt) %></li>
|
||||
<li><%= link_to "Kontakt", pages_path(:kontakt) %></li>
|
||||
<li><%= link_to "Parties", parties_path %></li>
|
||||
<li><%= link_to "Freunde", friends_path %></li>
|
||||
<li><%= link_to "Datenschutz", pages_path(:datenschutz) %></li>
|
||||
<li><%= link_to "Impressum", pages_path(:impressum) %></li>
|
||||
|
||||
42
app/views/parties/_form.html.erb
Normal file
42
app/views/parties/_form.html.erb
Normal file
@ -0,0 +1,42 @@
|
||||
<%= form_with(model: party, class: "contents") do |form| %>
|
||||
<% if party.errors.any? %>
|
||||
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-md mt-3">
|
||||
<h2><%= pluralize(party.errors.count, "error") %> prohibited this party from being saved:</h2>
|
||||
|
||||
<ul class="list-disc ml-6">
|
||||
<% party.errors.each do |error| %>
|
||||
<li><%= error.full_message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :title %>
|
||||
<%= form.text_field :title, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:title].none?, "border-red-400 focus:outline-red-600": party.errors[:title].any?}] %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :location %>
|
||||
<%= form.text_field :location, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:location].none?, "border-red-400 focus:outline-red-600": party.errors[:location].any?}] %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :start_date %>
|
||||
<%= form.date_field :start_date, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:start_date].none?, "border-red-400 focus:outline-red-600": party.errors[:start_date].any?}] %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :start_time %>
|
||||
<%= form.time_field :start_time, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:start_time].none?, "border-red-400 focus:outline-red-600": party.errors[:start_time].any?}] %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :status %>
|
||||
<%= form.text_field :status, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:status].none?, "border-red-400 focus:outline-red-600": party.errors[:status].any?}] %>
|
||||
</div>
|
||||
|
||||
<div class="inline">
|
||||
<%= form.submit class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
||||
</div>
|
||||
<% end %>
|
||||
22
app/views/parties/_party.html.erb
Normal file
22
app/views/parties/_party.html.erb
Normal file
@ -0,0 +1,22 @@
|
||||
<div id="<%= dom_id party %>" class="w-full sm:w-auto my-5 space-y-5">
|
||||
<div>
|
||||
<strong class="block font-medium mb-1">Title:</strong>
|
||||
<%= party.title %>
|
||||
</div>
|
||||
<div>
|
||||
<strong class="block font-medium mb-1">Location:</strong>
|
||||
<%= party.location %>
|
||||
</div>
|
||||
<div>
|
||||
<strong class="block font-medium mb-1">Start date:</strong>
|
||||
<%= party.start_date %>
|
||||
</div>
|
||||
<div>
|
||||
<strong class="block font-medium mb-1">Start time:</strong>
|
||||
<%= party.start_time %>
|
||||
</div>
|
||||
<div>
|
||||
<strong class="block font-medium mb-1">Status:</strong>
|
||||
<%= party.status %>
|
||||
</div>
|
||||
</div>
|
||||
10
app/views/parties/edit.html.erb
Normal file
10
app/views/parties/edit.html.erb
Normal file
@ -0,0 +1,10 @@
|
||||
<% content_for :title, "Editing party" %>
|
||||
|
||||
<div class="md:w-2/3 w-full">
|
||||
<h1 class="font-bold text-4xl">Editing party</h1>
|
||||
|
||||
<%= render "form", party: @party %>
|
||||
|
||||
<%= link_to "Show this party", @party, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
<%= link_to "Back to parties", parties_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
</div>
|
||||
29
app/views/parties/index.html.erb
Normal file
29
app/views/parties/index.html.erb
Normal file
@ -0,0 +1,29 @@
|
||||
<% content_for :title, "Parties" %>
|
||||
|
||||
<div class="w-full">
|
||||
<% if notice.present? %>
|
||||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block" id="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
|
||||
<div class="flex justify-between items-center">
|
||||
<h1 class="font-bold text-4xl">Parties</h1>
|
||||
<%= link_to "New party", new_party_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %>
|
||||
</div>
|
||||
|
||||
<div id="parties" class="min-w-full divide-y divide-gray-200 space-y-5">
|
||||
<% if @parties.any? %>
|
||||
<% @parties.each do |party| %>
|
||||
<div class="flex flex-col sm:flex-row justify-between items-center pb-5 sm:pb-0">
|
||||
<%= render party %>
|
||||
<div class="w-full sm:w-auto flex flex-col sm:flex-row space-x-2 space-y-2">
|
||||
<%= link_to "Show", party, class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
<%= link_to "Edit", edit_party_path(party), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
<%= button_to "Destroy", party, method: :delete, class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p class="text-center my-10">No parties found.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
9
app/views/parties/new.html.erb
Normal file
9
app/views/parties/new.html.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<% content_for :title, "New party" %>
|
||||
|
||||
<div class="md:w-2/3 w-full">
|
||||
<h1 class="font-bold text-4xl">New party</h1>
|
||||
|
||||
<%= render "form", party: @party %>
|
||||
|
||||
<%= link_to "Back to parties", parties_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
</div>
|
||||
15
app/views/parties/show.html.erb
Normal file
15
app/views/parties/show.html.erb
Normal file
@ -0,0 +1,15 @@
|
||||
<% content_for :title, "Showing party" %>
|
||||
|
||||
<div class="md:w-2/3 w-full">
|
||||
<% if notice.present? %>
|
||||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block" id="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
|
||||
<h1 class="font-bold text-4xl">Showing party</h1>
|
||||
|
||||
<%= render @party %>
|
||||
|
||||
<%= link_to "Edit this party", edit_party_path(@party), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
<%= link_to "Back to parties", parties_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
<%= button_to "Destroy this party", @party, method: :delete, form_class: "sm:inline-block mt-2 sm:mt-0 sm:ml-2", class: "w-full rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %>
|
||||
</div>
|
||||
Reference in New Issue
Block a user