aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-11-14 15:47:43 +0000
committerMatthew Lemon <y@yulqen.org>2024-11-14 15:47:43 +0000
commit6427b28c60c6ed0dfd637307d1ab4ffe65c1144d (patch)
tree156d280b94557f9606c053f6187aec2a21eb1b36 /app/controllers
parent1b64b0b709c5704de48120e20bdfad32f34b0b5d (diff)
Adds ResourceType model
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/pdfresources_controller.rb17
-rw-r--r--app/controllers/resource_types_controller.rb78
2 files changed, 87 insertions, 8 deletions
diff --git a/app/controllers/pdfresources_controller.rb b/app/controllers/pdfresources_controller.rb
index adacc64..a710404 100644
--- a/app/controllers/pdfresources_controller.rb
+++ b/app/controllers/pdfresources_controller.rb
@@ -69,16 +69,17 @@ class PdfresourcesController < ApplicationController
# Only allow a list of trusted parameters through.
def pdfresource_params
params.require(:pdfresource).permit(
- :name,
- :stripe_product_id,
- :price,
- :age_range,
- :curriculum,
- :feature_slot,
- :description,
+ :name,
+ :stripe_product_id,
+ :price,
+ :age_range,
+ :curriculum,
+ :resource_type_id,
+ :feature_slot,
+ :description,
:card_description,
:credits,
- pdfs: [],
+ pdfs: [],
thumbnails: []
)
end
diff --git a/app/controllers/resource_types_controller.rb b/app/controllers/resource_types_controller.rb
new file mode 100644
index 0000000..fdfb791
--- /dev/null
+++ b/app/controllers/resource_types_controller.rb
@@ -0,0 +1,78 @@
+class ResourceTypesController < ApplicationController
+ before_action :set_resource_type, only: %i[ show edit update destroy ]
+ before_action :require_admin, only: %i[ new create update destroy ]
+
+ # GET /resource_types or /resource_types.json
+ def index
+ @resource_types = ResourceType.all
+ end
+
+ # GET /resource_types/1 or /resource_types/1.json
+ def show
+ end
+
+ # GET /resource_types/new
+ def new
+ @resource_type = ResourceType.new
+ end
+
+ # GET /resource_types/1/edit
+ def edit
+ end
+
+ # POST /resource_types or /resource_types.json
+ def create
+ @resource_type = ResourceType.new(resource_type_params)
+
+ respond_to do |format|
+ if @resource_type.save
+ format.html { redirect_to @resource_type, notice: "Resource type was successfully created." }
+ format.json { render :show, status: :created, location: @resource_type }
+ else
+ format.html { render :new, status: :unprocessable_entity }
+ format.json { render json: @resource_type.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /resource_types/1 or /resource_types/1.json
+ def update
+ respond_to do |format|
+ if @resource_type.update(resource_type_params)
+ format.html { redirect_to @resource_type, notice: "Resource type was successfully updated." }
+ format.json { render :show, status: :ok, location: @resource_type }
+ else
+ format.html { render :edit, status: :unprocessable_entity }
+ format.json { render json: @resource_type.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /resource_types/1 or /resource_types/1.json
+ def destroy
+ @resource_type.destroy!
+
+ respond_to do |format|
+ format.html { redirect_to resource_types_path, status: :see_other, notice: "Resource type was successfully destroyed." }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_resource_type
+ @resource_type = ResourceType.find(params.expect(:id))
+ end
+
+ # Only allow a list of trusted parameters through.
+ def resource_type_params
+ params.expect(resource_type: [ :name ])
+ end
+
+ # must be admin!
+ def require_admin
+ unless Current.session.user&.is_admin
+ redirect_to root_path, notice: "You must be an admin to perform this action."
+ end
+ end
+end