Added vehicle scaffold
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

This commit is contained in:
2024-08-20 19:50:29 +02:00
parent 1bd24e08d0
commit 132ea2c51d
20 changed files with 379 additions and 1 deletions

View File

@@ -0,0 +1,73 @@
class VehiclesController < ApplicationController
before_action :set_vehicle, only: %i[ show edit update destroy ]
skip_before_action :authenticate
#has_many_attached :images
# GET /vehicles or /vehicles.json
def index
@vehicles = Vehicle.all
end
# GET /vehicles/1 or /vehicles/1.json
def show
end
# GET /vehicles/new
def new
@vehicle = Vehicle.new
end
# GET /vehicles/1/edit
def edit
end
# POST /vehicles or /vehicles.json
def create
@vehicle = Vehicle.new(vehicle_params)
respond_to do |format|
if @vehicle.save
format.html { redirect_to vehicle_url(@vehicle), notice: "Vehicle was successfully created." }
format.json { render :show, status: :created, location: @vehicle }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @vehicle.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /vehicles/1 or /vehicles/1.json
def update
respond_to do |format|
if @vehicle.update(vehicle_params)
format.html { redirect_to vehicle_url(@vehicle), notice: "Vehicle was successfully updated." }
format.json { render :show, status: :ok, location: @vehicle }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @vehicle.errors, status: :unprocessable_entity }
end
end
end
# DELETE /vehicles/1 or /vehicles/1.json
def destroy
@vehicle.destroy!
respond_to do |format|
format.html { redirect_to vehicles_url, notice: "Vehicle was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_vehicle
@vehicle = Vehicle.find(params[:id])
end
# Only allow a list of trusted parameters through.
def vehicle_params
params.require(:vehicle).permit(:vehicle_type, :car_brand, :model, :model_year, :fuel_type, :power_ps, :power_kw, :registered, :license_plate, :color, :note)
end
end

View File

@@ -0,0 +1,2 @@
module VehiclesHelper
end

3
app/models/vehicle.rb Normal file
View File

@@ -0,0 +1,3 @@
class Vehicle < ApplicationRecord
enum vehicle_type: { car: 0, truck: 1, motorcycle: 2, van: 3}
end

View File

@@ -0,0 +1,39 @@
<%= form_with(model: vehicle, class: "contents") do |form| %>
<% if vehicle.errors.any? %>
<div id="error_explanation" class="px-3 py-2 mt-3 font-medium text-red-500 rounded-lg bg-red-50">
<h2><%= pluralize(vehicle.errors.count, "error") %> prohibited this vehicle from being saved:</h2>
<ul>
<% vehicle.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="my-5">
<%= form.label :license_plate %>
<%= form.text_field :license_plate, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :vehicle_type %>
<%= form.text_field :vehicle_type, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :model_year %>
<%= form.text_field :model_year, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :car_brand %>
<%= form.text_field :car_brand, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :model %>
<%= form.text_field :model, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :fuel_type %>
<%= form.text_field :fuel_type, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
</div>
<% end %>

View File

@@ -0,0 +1,46 @@
<div id="<%= dom_id vehicle %>">
<p class="my-5">
<strong class="block mb-1 font-medium">Angemeldet:</strong>
<%= vehicle.registered %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">License plate:</strong>
<%= vehicle.license_plate %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Type:</strong>
<%= vehicle.vehicle_type %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Baujahr:</strong>
<%= vehicle.model_year %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Marke:</strong>
<%= vehicle.car_brand %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Modell:</strong>
<%= vehicle.model %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Treibstoffart:</strong>
<%= vehicle.fuel_type %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">PS:</strong>
<%= vehicle.power_ps %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">KW:</strong>
<%= vehicle.power_kw %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Farbe:</strong>
<%= vehicle.color %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Notizen:</strong>
<%= vehicle.note %>
</p>
</div>

View File

@@ -0,0 +1,2 @@
json.extract! vehicle, :id, :license_plate, :type, :model_year, :car_brand, :model, :fuel_type, :created_at, :updated_at
json.url vehicle_url(vehicle, format: :json)

View File

@@ -0,0 +1,8 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">Editing vehicle</h1>
<%= render "form", vehicle: @vehicle %>
<%= link_to "Show this vehicle", @vehicle, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to "Back to vehicles", vehicles_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>

View File

@@ -0,0 +1,21 @@
<div class="w-full">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>
<% content_for :title, "Vehicles" %>
<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl">Vehicles</h1>
<%= link_to "New vehicle", new_vehicle_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div>
<div id="vehicles" class="min-w-full">
<% @vehicles.each do |vehicle| %>
<%= render vehicle %>
<p>
<%= link_to "Show this vehicle", vehicle, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</p>
<% end %>
</div>
</div>

View File

@@ -0,0 +1 @@
json.array! @vehicles, partial: "vehicles/vehicle", as: :vehicle

View File

@@ -0,0 +1,7 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">New vehicle</h1>
<%= render "form", vehicle: @vehicle %>
<%= link_to "Back to vehicles", vehicles_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>

View File

@@ -0,0 +1,15 @@
<div class="mx-auto md:w-2/3 w-full flex">
<div class="mx-auto">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>
<%= render @vehicle %>
<%= link_to "Edit this vehicle", edit_vehicle_path(@vehicle), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to "Back to vehicles", vehicles_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<div class="inline-block ml-2">
<%= button_to "Destroy this vehicle", @vehicle, method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
</div>
</div>
</div>

View File

@@ -0,0 +1 @@
json.partial! "vehicles/vehicle", vehicle: @vehicle