1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
class PdfresourcesController < ApplicationController
before_action :set_pdfresource, only: %i[ show edit update destroy ]
before_action :require_admin, only: %i[ index new create 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
PdfProcessorService.new(@pdfresource).process_pdfs
format.html { redirect_to @pdfresource, notice: "Resource 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.require(:pdfresource).permit(
:name,
:stripe_product_id,
:price,
:age_range,
:curriculum,
:resource_type_id,
:feature_slot,
:description,
:card_description,
:credits,
pdfs: [],
thumbnails: []
)
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
|