From 5a9063a04b5a81de31566ad641728ca06fe96927 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 13 Nov 2024 17:12:14 +0000 Subject: Adds some validation and further work on the form --- app/models/pdfresource.rb | 3 + app/views/pdfresources/_form.html.erb | 83 ++++++++++++++----------- app/views/pdfresources/_pdfresource.html.erb | 93 +++++++++++++++------------- app/views/pdfresources/edit.html.erb | 2 +- app/views/pdfresources/index.html.erb | 2 +- 5 files changed, 102 insertions(+), 81 deletions(-) (limited to 'app') diff --git a/app/models/pdfresource.rb b/app/models/pdfresource.rb index 6131034..6614f66 100644 --- a/app/models/pdfresource.rb +++ b/app/models/pdfresource.rb @@ -1,4 +1,7 @@ class Pdfresource < ApplicationRecord has_many_attached :pdfs has_many_attached :thumbnails + validates :feature_slot, + numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 3, allow_nil: true }, + allow_nil: true end diff --git a/app/views/pdfresources/_form.html.erb b/app/views/pdfresources/_form.html.erb index 39c8314..86b1ca5 100644 --- a/app/views/pdfresources/_form.html.erb +++ b/app/views/pdfresources/_form.html.erb @@ -12,61 +12,74 @@ <% end %>
- <%= form.label :name, class: "font-bold" %> + <%= form.label :name, class: "font-bold" %> <%= form.text_field :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
- +
- <%= form.label :description, class: "font-bold" %> + <%= form.label :description, class: "font-bold" %> <%= form.textarea :description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>

Go to two with the description here. THIS WILL BE RICH TEXT.

- <%= form.label :card_description, class: "font-bold" %> + <%= form.label :card_description, class: "font-bold" %> <%= form.textarea :card_description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -

This is a much shorter description that is used inside the "card" boxes on the listings page.

+

This is a much shorter description that is used inside the "card" boxes on the + listings page.

- <%= form.label :pdfs, "Resource PDFs", class: "font-bold" %> + <%= form.label :pdfs, "Resource PDFs", class: "font-bold" %> <%= form.file_field :pdfs, multiple: true, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -

You can upload up to 10 PDFs per resource.

+

You can upload up to 10 PDFs per resource. The original files were: + <% pdfresource.pdfs.each do |pdf| %> + + <%= pdf.filename %> + + <% end %> +

- <%= form.label :thumbnails, class: "font-bold" %> + <%= form.label :thumbnails, class: "font-bold" %> <%= form.file_field :thumbnails, multiple: true, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -

You can upload up to 10 thumbnails per resource.

-
+

You can upload up to 10 thumbnails per resource. The original files were: + <% pdfresource.thumbnails.each do |thumbnail| %> + + <%= thumbnail.filename %> + + <% end.to_sentence %> +

+ -
- <%= form.label :price, class: "font-bold" %> - <%= form.number_field :price, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -

This is what we will sell it for!

-
- -
- <%= form.label :stripe_product_id, "Stripe Product ID", class: "font-bold" %> - <%= form.text_field :stripe_product_id, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -
+
+ <%= form.label :price, class: "font-bold" %> + <%= form.number_field :price, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +

This is what we will sell it for!

+
-
- <%= form.label :age_range, class: "font-bold" %> - <%= form.text_field :age_range, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -
+
+ <%= form.label :stripe_product_id, "Stripe Product ID", class: "font-bold" %> + <%= form.text_field :stripe_product_id, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
-
- <%= form.label :curriculum, class: "font-bold" %> - <%= form.text_field :curriculum, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -
+
+ <%= form.label :age_range, class: "font-bold" %> + <%= form.text_field :age_range, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
-
- <%= 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 :curriculum, class: "font-bold" %> + <%= form.text_field :curriculum, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
-
- <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> -
+
+ <%= 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.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
<% end %> diff --git a/app/views/pdfresources/_pdfresource.html.erb b/app/views/pdfresources/_pdfresource.html.erb index 2e0d86c..7a2409e 100644 --- a/app/views/pdfresources/_pdfresource.html.erb +++ b/app/views/pdfresources/_pdfresource.html.erb @@ -1,55 +1,60 @@ -
-

-

- <%= image_tag url_for(pdfresource.thumbnails.first), class: "object-cover"%> -
-

- -

- <%= pdfresource.name %> -

- -

- <%= pdfresource.card_description %> -

- -

- Stripe product: - <%= pdfresource.stripe_product_id %> -

- -

- Pdfs: - <% pdfresource.pdfs.each do |pdf| %> +

+
+ <%= image_tag url_for(pdfresource.thumbnails.first), size: "500x100", class: "rounded-t-lg" %> +
+ +
+

+ <%= pdfresource.name %> +

+ +
+ #photography + #travel + #winter +
+ +

+ <%= pdfresource.card_description %> +

+ +

+ Stripe product: + <%= pdfresource.stripe_product_id %> +

+ +

+ Pdfs: + <% pdfresource.pdfs.each do |pdf| %>

<%= link_to pdf.filename, pdf %>
<% end %> -

+

-

- Price: - <%= pdfresource.price %> -

+

+ Price: + <%= pdfresource.price %> +

-

- Age range: - <%= pdfresource.age_range %> -

+

+ Age range: + <%= pdfresource.age_range %> +

-

- Curriculum: - <%= pdfresource.curriculum %> -

+

+ Curriculum: + <%= pdfresource.curriculum %> +

-

- Feature slot: - <%= pdfresource.feature_slot %> -

+

+ Feature slot: + <%= pdfresource.feature_slot %> +

-

- Description: - <%= pdfresource.description %> -

+

+ Description: + <%= pdfresource.description %> +

<%= link_to "Show this pdfresource", pdfresource, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> diff --git a/app/views/pdfresources/edit.html.erb b/app/views/pdfresources/edit.html.erb index 6738cf1..aa8d60e 100644 --- a/app/views/pdfresources/edit.html.erb +++ b/app/views/pdfresources/edit.html.erb @@ -1,5 +1,5 @@

-

Editing pdfresource

+

Editing <%= @pdfresource.name %>

<%= render "form", pdfresource: @pdfresource %> diff --git a/app/views/pdfresources/index.html.erb b/app/views/pdfresources/index.html.erb index 309dcdd..158e505 100644 --- a/app/views/pdfresources/index.html.erb +++ b/app/views/pdfresources/index.html.erb @@ -9,7 +9,7 @@

Featured Resources

-
+
<% @pdfresources.where("feature_slot < 4").each do |pdfresource| %> <%= render pdfresource %> <% end %> -- cgit v1.2.3