Added images to vehicles
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 20:26:06 +02:00
parent 132ea2c51d
commit f50bf2fa5f
5 changed files with 25 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
class HomeController < ApplicationController
skip_before_action :authenticate
def index
end
end

View File

@@ -1,8 +1,8 @@
class VehiclesController < ApplicationController
before_action :set_vehicle, only: %i[ show edit update destroy ]
skip_before_action :authenticate
#has_many_attached :images
# has_many_attached :images
# GET /vehicles or /vehicles.json
def index
@@ -68,6 +68,6 @@ class VehiclesController < ApplicationController
# 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)
params.require(:vehicle).permit(:vehicle_type, :car_brand, :model, :model_year, :fuel_type, :power_ps, :power_kw, :registered, :license_plate, :color, :note, images: [])
end
end

View File

@@ -1,3 +1,10 @@
class Vehicle < ApplicationRecord
enum vehicle_type: { car: 0, truck: 1, motorcycle: 2, van: 3}
has_many_attached :images do |attachable|
attachable.variant :thumb, resize_to_limit: [ 100, 100 ]
attachable.variant :medium, resize_to_limit: [ 600, 600 ]
attachable.variant :big, resize_to_limit: [ 1000, 1000 ]
attachable.variant :hugh, resize_to_limit: [ 1920, 1920 ]
end
enum vehicle_type: { car: 0, truck: 1, motorcycle: 2, van: 3 }
end

View File

@@ -9,6 +9,13 @@
</ul>
</div>
<% end %>
<div class="my-5">
<%= form.label :images %>
<% vehicle.images.each do |image| %>
<%= form.hidden_field :images, multiple: true, value: image.signed_id %>
<% end %>
<%= form.file_field :images, multiple: true, 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 :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" %>

View File

@@ -1,4 +1,9 @@
<div id="<%= dom_id vehicle %>">
<p class=my-5><strong class="block mb-1 font-medium">Bilder:</strong>
<% vehicle.images.each do |image| %>
<%= image_tag image.variant(:medium) %>
<% end %>
</p>
<p class="my-5">
<strong class="block mb-1 font-medium">Angemeldet:</strong>
<%= vehicle.registered %>