Mercurial > zeropaste
annotate app/controllers/pastes_controller.rb @ 52:4c782f8d835b
Merge.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Thu, 04 Oct 2012 04:23:39 +0700 |
parents | c09020fc73f5 |
children | 817c54a72b58 |
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 |
2 | 3 # GET /pastes/1 |
4 # GET /pastes/1.json | |
5 def show | |
6 @paste = Paste.find(params[:id]) | |
7 | |
8 respond_to do |format| | |
9 format.html # show.html.erb | |
7 | 10 format.txt # show.html.erb |
2 | 11 end |
12 end | |
13 | |
14 # GET /pastes/new | |
15 # GET /pastes/new.json | |
16 def new | |
17 @paste = Paste.new | |
10 | 18 begin |
19 @paste.paste = Paste.find(params[:base]).paste | |
20 rescue | |
21 end | |
2 | 22 |
23 respond_to do |format| | |
24 format.html # new.html.erb | |
25 format.json { render :json => @paste } | |
26 end | |
27 end | |
28 | |
29 # POST /pastes | |
30 # POST /pastes.json | |
31 def create | |
32 @paste = Paste.new | |
33 @paste.paste = params[:paste][:paste] | |
34 @paste.ip = request.remote_ip | |
35 | |
32
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
36 begin |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
37 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
|
38 if @paste.save |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
39 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
|
40 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
|
41 else |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
42 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
|
43 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
|
44 end |
2 | 45 end |
32
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
46 rescue ActiveRecord::RecordNotUnique |
59ef6698fa0d
Rescue from not unique error by redirecting to previously pasted paste.
Edho Arief <edho@myconan.net>
parents:
12
diff
changeset
|
47 redirect_to paste_path(Paste.where(:ip => @paste.ip, :paste_hash => @paste.paste_hash).first) |
2 | 48 end |
49 end | |
50 | |
51 end |