Mercurial > zeropaste
annotate app/controllers/pastes_controller.rb @ 490:a39bc79fcb1a
Specify path to builds directory
author | nanaya <me@nanaya.net> |
---|---|
date | Tue, 17 Jan 2023 02:36:38 +0900 |
parents | f11862e58af4 |
children |
rev | line source |
---|---|
2 | 1 class PastesController < ApplicationController |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
2 # GET /1 |
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
3 # GET /1.txt |
2 | 4 def show |
212
186b4674bcbe
Add controller support for is_private flag
Edho Arief <edho@myconan.net>
parents:
211
diff
changeset
|
5 @paste = Paste.safe_find(params[:id]) |
329 | 6 return head :not_found unless @paste |
2 | 7 |
464 | 8 if params[:id] != @paste.to_param |
9 redirect_to :action => :show, | |
10 :id => @paste.to_param, | |
11 :format => params[:format] | |
12 return | |
13 end | |
14 | |
2 | 15 respond_to do |format| |
366 | 16 format.html |
17 format.txt | |
2 | 18 end |
19 end | |
20 | |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
21 # GET / |
2 | 22 def new |
23 @paste = Paste.new | |
189
b4b7a29b70f6
Initial work for paste deletion.
Edho Arief <edho@myconan.net>
parents:
183
diff
changeset
|
24 @paste.set_paste_key |
240
16251b94eb6c
Whoops, forgot to secure the "new paste based on ##"
edogawaconan <me@myconan.net>
parents:
229
diff
changeset
|
25 @paste.paste = Paste.safe_find(params[:base]).try(:paste) |
2 | 26 |
27 respond_to do |format| | |
28 format.html # new.html.erb | |
29 end | |
30 end | |
31 | |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
32 # POST / |
2 | 33 # POST /pastes.json |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
34 # POST /pastes.txt |
2 | 35 def create |
373
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
36 created, @paste, @fresh = Paste.graceful_create paste_params.merge(:ip => request.remote_ip) |
2 | 37 |
373
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
38 respond_to do |format| |
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
39 if created |
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
40 if @fresh |
329 | 41 format.html { redirect_to @paste, :notice => "Paste was successfully created." } |
32
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
42 format.json { render :json => @paste, :status => :created, :location => @paste } |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
43 else |
373
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
44 format.html { redirect_to paste_path(@paste) } |
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
45 format.json { render :json => @paste } |
32
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
46 end |
373
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
47 else |
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
48 flash.now[:alert] = @paste.errors.full_messages.to_sentence |
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
49 format.html { render :action => "new" } |
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
50 format.json { render :json => @paste.errors, :status => :unprocessable_entity } |
2 | 51 end |
373
6e3e1e7b0212
Handle unique error in model instead of controller.
nanaya <me@myconan.net>
parents:
366
diff
changeset
|
52 format.txt |
2 | 53 end |
54 end | |
55 | |
189
b4b7a29b70f6
Initial work for paste deletion.
Edho Arief <edho@myconan.net>
parents:
183
diff
changeset
|
56 def destroy |
212
186b4674bcbe
Add controller support for is_private flag
Edho Arief <edho@myconan.net>
parents:
211
diff
changeset
|
57 @paste = Paste.safe_find(params[:id]) |
265
6cca1ab53337
Infinitely better error messages and notice.
edogawaconan <me@myconan.net>
parents:
240
diff
changeset
|
58 if @paste.safe_destroy(params[:paste][:key]) |
6cca1ab53337
Infinitely better error messages and notice.
edogawaconan <me@myconan.net>
parents:
240
diff
changeset
|
59 redirect_to root_path, :notice => "Paste ##{params[:id]} deleted" |
189
b4b7a29b70f6
Initial work for paste deletion.
Edho Arief <edho@myconan.net>
parents:
183
diff
changeset
|
60 else |
283 | 61 flash.now[:alert] = @paste.errors.full_messages.to_sentence |
265
6cca1ab53337
Infinitely better error messages and notice.
edogawaconan <me@myconan.net>
parents:
240
diff
changeset
|
62 render :show |
189
b4b7a29b70f6
Initial work for paste deletion.
Edho Arief <edho@myconan.net>
parents:
183
diff
changeset
|
63 end |
b4b7a29b70f6
Initial work for paste deletion.
Edho Arief <edho@myconan.net>
parents:
183
diff
changeset
|
64 end |
b4b7a29b70f6
Initial work for paste deletion.
Edho Arief <edho@myconan.net>
parents:
183
diff
changeset
|
65 |
211 | 66 private |
320 | 67 |
211 | 68 def paste_params |
417
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
378
diff
changeset
|
69 params.require(:paste).permit(:paste, :paste_gzip, :paste_gzip_base64, :is_private, :key, :language) |
211 | 70 end |
2 | 71 end |