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