diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/application_helper.rb | 8 | ||||
-rw-r--r-- | app/helpers/pdfresources_helper.rb | 2 | ||||
-rw-r--r-- | app/models/pdfresource.rb | 3 | ||||
-rw-r--r-- | app/views/pdfresources/_form.html.erb | 17 |
4 files changed, 22 insertions, 8 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..b1c2b1e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,10 @@ module ApplicationHelper + def required_label_tag(form, field, text = nil) + label_content = text || field.to_s.titleize + required = form.object.class.validators_on(field).any? { |v| v.is_a?(ActiveRecord::Validations::PresenceValidator) } + + form.label field, class: "font-bold" do + required ? "#{label_content} <span class='text-red-500'>*</span>".html_safe : label_content + end + end end diff --git a/app/helpers/pdfresources_helper.rb b/app/helpers/pdfresources_helper.rb deleted file mode 100644 index 1f400cc..0000000 --- a/app/helpers/pdfresources_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module PdfresourcesHelper -end diff --git a/app/models/pdfresource.rb b/app/models/pdfresource.rb index a5ef56d..86e600c 100644 --- a/app/models/pdfresource.rb +++ b/app/models/pdfresource.rb @@ -6,7 +6,8 @@ class Pdfresource < ApplicationRecord numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 3, allow_nil: true }, allow_nil: true validate :validate_pdf_count - validates :name, :thumbnails, presence: true + validates :name, :thumbnails, :description, :card_description, :pdfs, :credits, presence: true + def validate_pdf_count if pdfs.size > 10 diff --git a/app/views/pdfresources/_form.html.erb b/app/views/pdfresources/_form.html.erb index 0739bc9..8b439b0 100644 --- a/app/views/pdfresources/_form.html.erb +++ b/app/views/pdfresources/_form.html.erb @@ -12,25 +12,25 @@ <% end %> <div class="my-5"> - <%= form.label :name, class: "font-bold" %> + <%= required_label_tag(form, :name) %> <%= form.text_field :name, 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 :description, class: "font-bold" %> + <%= required_label_tag(form, :description) %> <%= form.textarea :description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> <p class="text-sm text-gray-700">Go to two with the description here. THIS WILL BE RICH TEXT.</p> </div> <div class="my-5"> - <%= form.label :card_description, class: "font-bold" %> + <%= required_label_tag(form, :card_description) %> <%= 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" %> <p class="text-sm text-gray-700">This is a much shorter description that is used inside the "card" boxes on the listings page.</p> </div> <div class="my-5"> - <%= form.label :pdfs, "Resource PDFs", class: "font-bold" %> + <%= required_label_tag(form, :pdfs) %> <%= 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" %> <p class="text-sm text-gray-700">You can upload up to 10 PDFs per resource. The original files were:</p> <ul class="list-disc font-bold text-green-500"> @@ -41,7 +41,7 @@ </div> <div class="my-5"> - <%= form.label :thumbnails, class: "font-bold" %> + <%= required_label_tag(form, :thumbnails) %> <%= 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" %> <p class="text-sm text-gray-700">You can upload up to 10 thumbnails per resource. The original files were:</p> <ul class="list-disc font-bold text-green-500"> @@ -58,6 +58,13 @@ </div> <div class="my-5"> + <%= required_label_tag(form, :credits) %> + <%= form.number_field :credits, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> + <p class="text-sm text-gray-700">Number of credits required to purchase this resource.</p> + </div> + + + <div class="my-5"> <%= 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" %> </div> |