From b8d7a7cf7e78fe384c6c6e8e6812a252084ce1f0 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 11 Nov 2024 16:33:24 +0000 Subject: Adds first pdfresource model --- app/controllers/pdfresources_controller.rb | 70 +++++++++++++++++++++++ app/helpers/pdfresources_helper.rb | 2 + app/models/pdfresource.rb | 4 ++ app/views/pdfresources/_form.html.erb | 67 ++++++++++++++++++++++ app/views/pdfresources/_pdfresource.html.erb | 56 ++++++++++++++++++ app/views/pdfresources/_pdfresource.json.jbuilder | 14 +++++ app/views/pdfresources/edit.html.erb | 8 +++ app/views/pdfresources/index.html.erb | 21 +++++++ app/views/pdfresources/index.json.jbuilder | 1 + app/views/pdfresources/new.html.erb | 7 +++ app/views/pdfresources/show.html.erb | 15 +++++ app/views/pdfresources/show.json.jbuilder | 1 + 12 files changed, 266 insertions(+) create mode 100644 app/controllers/pdfresources_controller.rb create mode 100644 app/helpers/pdfresources_helper.rb create mode 100644 app/models/pdfresource.rb create mode 100644 app/views/pdfresources/_form.html.erb create mode 100644 app/views/pdfresources/_pdfresource.html.erb create mode 100644 app/views/pdfresources/_pdfresource.json.jbuilder create mode 100644 app/views/pdfresources/edit.html.erb create mode 100644 app/views/pdfresources/index.html.erb create mode 100644 app/views/pdfresources/index.json.jbuilder create mode 100644 app/views/pdfresources/new.html.erb create mode 100644 app/views/pdfresources/show.html.erb create mode 100644 app/views/pdfresources/show.json.jbuilder (limited to 'app') diff --git a/app/controllers/pdfresources_controller.rb b/app/controllers/pdfresources_controller.rb new file mode 100644 index 0000000..068b61a --- /dev/null +++ b/app/controllers/pdfresources_controller.rb @@ -0,0 +1,70 @@ +class PdfresourcesController < ApplicationController + before_action :set_pdfresource, only: %i[ show edit update destroy ] + + # GET /pdfresources or /pdfresources.json + def index + @pdfresources = Pdfresource.all + end + + # GET /pdfresources/1 or /pdfresources/1.json + def show + end + + # GET /pdfresources/new + def new + @pdfresource = Pdfresource.new + end + + # GET /pdfresources/1/edit + def edit + end + + # POST /pdfresources or /pdfresources.json + def create + @pdfresource = Pdfresource.new(pdfresource_params) + + respond_to do |format| + if @pdfresource.save + format.html { redirect_to @pdfresource, notice: "Pdfresource was successfully created." } + format.json { render :show, status: :created, location: @pdfresource } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @pdfresource.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /pdfresources/1 or /pdfresources/1.json + def update + respond_to do |format| + if @pdfresource.update(pdfresource_params) + format.html { redirect_to @pdfresource, notice: "Pdfresource was successfully updated." } + format.json { render :show, status: :ok, location: @pdfresource } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @pdfresource.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /pdfresources/1 or /pdfresources/1.json + def destroy + @pdfresource.destroy! + + respond_to do |format| + format.html { redirect_to pdfresources_path, status: :see_other, notice: "Pdfresource was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_pdfresource + @pdfresource = Pdfresource.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def pdfresource_params + params.expect(pdfresource: [ :name, :stripe_product_id, :price, :age_range, :curriculum, :feature_slot, :description, :card_description, pdfs: [], thumbnails: [] ]) + end +end diff --git a/app/helpers/pdfresources_helper.rb b/app/helpers/pdfresources_helper.rb new file mode 100644 index 0000000..1f400cc --- /dev/null +++ b/app/helpers/pdfresources_helper.rb @@ -0,0 +1,2 @@ +module PdfresourcesHelper +end diff --git a/app/models/pdfresource.rb b/app/models/pdfresource.rb new file mode 100644 index 0000000..6131034 --- /dev/null +++ b/app/models/pdfresource.rb @@ -0,0 +1,4 @@ +class Pdfresource < ApplicationRecord + has_many_attached :pdfs + has_many_attached :thumbnails +end diff --git a/app/views/pdfresources/_form.html.erb b/app/views/pdfresources/_form.html.erb new file mode 100644 index 0000000..a75121a --- /dev/null +++ b/app/views/pdfresources/_form.html.erb @@ -0,0 +1,67 @@ +<%= form_with(model: pdfresource, class: "contents") do |form| %> + <% if pdfresource.errors.any? %> +
+

<%= pluralize(pdfresource.errors.count, "error") %> prohibited this pdfresource from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name %> + <%= 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 :stripe_product_id %> + <%= 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 :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" %> +
+ +
+ <%= form.label :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" %> +
+ +
+ <%= form.label :price %> + <%= form.text_field :price, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.label :age_range %> + <%= 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 :curriculum %> + <%= 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 :feature_slot %> + <%= 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 :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" %> +
+ +
+ <%= form.label :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" %> +
+ +
+ <%= 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 new file mode 100644 index 0000000..d947dd1 --- /dev/null +++ b/app/views/pdfresources/_pdfresource.html.erb @@ -0,0 +1,56 @@ +
+

+ Name: + <%= pdfresource.name %> +

+ +

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

+ +

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

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

+ +

+ Thumbnails: + <% pdfresource.thumbnails.each do |thumbnail| %> +

<%= link_to thumbnail.filename, thumbnail %>
+ <% end %> +

+ +

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

+ +

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

+ +

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

+ +

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

+ +

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

+ +

+ Card description: + <%= pdfresource.card_description %> +

+ +
diff --git a/app/views/pdfresources/_pdfresource.json.jbuilder b/app/views/pdfresources/_pdfresource.json.jbuilder new file mode 100644 index 0000000..6bb63a6 --- /dev/null +++ b/app/views/pdfresources/_pdfresource.json.jbuilder @@ -0,0 +1,14 @@ +json.extract! pdfresource, :id, :name, :stripe_product_id, :pdfs, :thumbnails, :price, :age_range, :curriculum, :feature_slot, :description, :card_description, :created_at, :updated_at +json.url pdfresource_url(pdfresource, format: :json) +json.pdfs do + json.array!(pdfresource.pdfs) do |pdf| + json.id pdf.id + json.url url_for(pdf) + end +end +json.thumbnails do + json.array!(pdfresource.thumbnails) do |thumbnail| + json.id thumbnail.id + json.url url_for(thumbnail) + end +end diff --git a/app/views/pdfresources/edit.html.erb b/app/views/pdfresources/edit.html.erb new file mode 100644 index 0000000..6738cf1 --- /dev/null +++ b/app/views/pdfresources/edit.html.erb @@ -0,0 +1,8 @@ +
+

Editing pdfresource

+ + <%= render "form", pdfresource: @pdfresource %> + + <%= link_to "Show this pdfresource", @pdfresource, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Back to pdfresources", pdfresources_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/pdfresources/index.html.erb b/app/views/pdfresources/index.html.erb new file mode 100644 index 0000000..ff29982 --- /dev/null +++ b/app/views/pdfresources/index.html.erb @@ -0,0 +1,21 @@ +
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + + <% content_for :title, "Pdfresources" %> + +
+

Pdfresources

+ <%= link_to "New pdfresource", new_pdfresource_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> +
+ +
+ <% @pdfresources.each do |pdfresource| %> + <%= render pdfresource %> +

+ <%= link_to "Show this pdfresource", pdfresource, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +

+ <% end %> +
+
diff --git a/app/views/pdfresources/index.json.jbuilder b/app/views/pdfresources/index.json.jbuilder new file mode 100644 index 0000000..945d359 --- /dev/null +++ b/app/views/pdfresources/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @pdfresources, partial: "pdfresources/pdfresource", as: :pdfresource diff --git a/app/views/pdfresources/new.html.erb b/app/views/pdfresources/new.html.erb new file mode 100644 index 0000000..5bd072b --- /dev/null +++ b/app/views/pdfresources/new.html.erb @@ -0,0 +1,7 @@ +
+

New pdfresource

+ + <%= render "form", pdfresource: @pdfresource %> + + <%= link_to "Back to pdfresources", pdfresources_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/pdfresources/show.html.erb b/app/views/pdfresources/show.html.erb new file mode 100644 index 0000000..3c4fe66 --- /dev/null +++ b/app/views/pdfresources/show.html.erb @@ -0,0 +1,15 @@ +
+
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + + <%= render @pdfresource %> + + <%= link_to "Edit this pdfresource", edit_pdfresource_path(@pdfresource), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Back to pdfresources", pdfresources_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
+ <%= button_to "Destroy this pdfresource", @pdfresource, method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> +
+
+
diff --git a/app/views/pdfresources/show.json.jbuilder b/app/views/pdfresources/show.json.jbuilder new file mode 100644 index 0000000..492dde3 --- /dev/null +++ b/app/views/pdfresources/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "pdfresources/pdfresource", pdfresource: @pdfresource -- cgit v1.2.3