Mercurial > zeropaste
annotate app/controllers/pastes_controller.rb @ 75:8f6a0204b2a7
Disabled responding to pastes#new format json.
Nothing can normally reach that right now.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Thu, 04 Oct 2012 11:01:38 +0700 |
parents | 48598fc65c20 |
children | 2fb80ca710e0 |
rev | line source |
---|---|
2 | 1 class PastesController < ApplicationController |
48
f649b46fca4f
Cache all the things! Or just the show page.
Edho Arief <edho@myconan.net>
parents:
32
diff
changeset
|
2 caches_page :show |
73 | 3 |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
4 # GET /1 |
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
5 # GET /1.txt |
2 | 6 def show |
53 | 7 id = params[:id].to_i |
8 if id.to_s != params[:id] | |
9 redirect_to paste_path(id) | |
10 return | |
11 end | |
2 | 12 @paste = Paste.find(params[:id]) |
13 | |
14 respond_to do |format| | |
15 format.html # show.html.erb | |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
16 format.txt # show.txt.erb |
2 | 17 end |
18 end | |
19 | |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
20 # GET / |
2 | 21 def new |
22 @paste = Paste.new | |
10 | 23 begin |
24 @paste.paste = Paste.find(params[:base]).paste | |
25 rescue | |
26 end | |
2 | 27 |
28 respond_to do |format| | |
29 format.html # new.html.erb | |
30 end | |
31 end | |
32 | |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
33 # POST / |
2 | 34 # POST /pastes.json |
74
48598fc65c20
Fixed comments on pastes_controller.
Edho Arief <edho@myconan.net>
parents:
73
diff
changeset
|
35 # POST /pastes.txt |
2 | 36 def create |
37 @paste = Paste.new | |
69
be561c3967ee
Safety net to ignore invalid post requests.
Edho Arief <edho@myconan.net>
parents:
67
diff
changeset
|
38 if params[:paste] and not params[:paste][:paste].blank? |
be561c3967ee
Safety net to ignore invalid post requests.
Edho Arief <edho@myconan.net>
parents:
67
diff
changeset
|
39 @paste.paste = params[:paste][:paste] |
be561c3967ee
Safety net to ignore invalid post requests.
Edho Arief <edho@myconan.net>
parents:
67
diff
changeset
|
40 @paste.ip = request.remote_ip |
be561c3967ee
Safety net to ignore invalid post requests.
Edho Arief <edho@myconan.net>
parents:
67
diff
changeset
|
41 end |
2 | 42 |
32
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
43 begin |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
44 respond_to do |format| |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
45 if @paste.save |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
46 format.html { redirect_to @paste, :notice => 'Paste was successfully created.' } |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
47 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
|
48 else |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
49 format.html { render :action => "new" } |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
50 format.json { render :json => @paste.errors, :status => :unprocessable_entity } |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
51 end |
67
f7b7a39fb48c
Allow post in txt format pt. 2 (view and controller).
Edho Arief <edho@myconan.net>
parents:
53
diff
changeset
|
52 format.txt |
2 | 53 end |
32
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
54 rescue ActiveRecord::RecordNotUnique |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
55 redirect_to paste_path(Paste.where(:ip => @paste.ip, :paste_hash => @paste.paste_hash).first) |
2 | 56 end |
57 end | |
58 | |
59 end |