From 851521dc475e3d434ff8e13bd9f9e558aa9af772 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 14 Nov 2024 16:14:33 +0000 Subject: Improved the feature slot handling - can now remove feature_slot value --- app/models/pdfresource.rb | 3 ++- app/views/pdfresources/_form.html.erb | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/pdfresource.rb b/app/models/pdfresource.rb index 4fa2292..8e59972 100644 --- a/app/models/pdfresource.rb +++ b/app/models/pdfresource.rb @@ -4,7 +4,8 @@ class Pdfresource < ApplicationRecord has_many_attached :pdf_snapshots belongs_to :resource_type validates :feature_slot, - numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 3, allow_nil: true }, + inclusion: { in: [ 1, 2, 3 ], message: "must be 1, 2, or 3" }, + uniqueness: { message: "is already taken by another featured resource" }, allow_nil: true validate :validate_pdf_count validates :name, :thumbnails, :description, :card_description, :pdfs, :credits, presence: true diff --git a/app/views/pdfresources/_form.html.erb b/app/views/pdfresources/_form.html.erb index a15bd67..a3922c9 100644 --- a/app/views/pdfresources/_form.html.erb +++ b/app/views/pdfresources/_form.html.erb @@ -92,7 +92,7 @@
<%= required_label_tag(form, :resource_type) %> - <%= form.collection_select :resource_type_id, ResourceType.all, :id, :name, {}, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> + <%= form.collection_select :resource_type_id, ResourceType.all, :id, :name, { prompt: "Select resource type" }, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
@@ -111,8 +111,17 @@
- <%= form.label :feature_slot, class: "font-bold" %> - <%= form.number_field :feature_slot, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> + <%= form.label :feature_slot, "Feature Position", class: "font-bold" %> + <%= form.select :feature_slot, + options_for_select([ + ["Not Featured", nil], + ["Position 1", 1], + ["Position 2", 2], + ["Position 3", 3] + ], pdfresource.feature_slot), + { include_blank: false }, + class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +

Select a position to feature this resource, or "Not Featured" to remove from featured items. Only three resources can be featured at a time.

-- cgit v1.2.3