annotate app/controllers/pastes_controller.rb @ 2:42de15334db1

Added the pastes.
author Edho Arief <edho@myconan.net>
date Sun, 26 Aug 2012 11:28:23 -0700
parents
children 23178d3de796
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
1 class PastesController < ApplicationController
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
2 # GET /pastes
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
3 # GET /pastes.json
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
4 def index
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
5 @pastes = Paste.all
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
6
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
7 respond_to do |format|
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
8 format.html # index.html.erb
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
9 format.json { render :json => @pastes }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
10 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
11 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
12
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
13 # GET /pastes/1
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
14 # GET /pastes/1.json
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
15 def show
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
16 @paste = Paste.find(params[:id])
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
17
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
18 respond_to do |format|
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
19 format.html # show.html.erb
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
20 format.json { render :json => @paste }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
21 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
22 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
23
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
24 # GET /pastes/new
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
25 # GET /pastes/new.json
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
26 def new
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
27 @paste = Paste.new
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
28
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
29 respond_to do |format|
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
30 format.html # new.html.erb
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
31 format.json { render :json => @paste }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
32 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
33 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
34
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
35 # GET /pastes/1/edit
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
36 def edit
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
37 @paste = Paste.find(params[:id])
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
38 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
39
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
40 # POST /pastes
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
41 # POST /pastes.json
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
42 def create
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
43 @paste = Paste.new
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
44 @paste.paste = params[:paste][:paste]
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
45 @paste.ip = request.remote_ip
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
46
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
47 respond_to do |format|
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
48 if @paste.save
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
49 format.html { redirect_to @paste, :notice => 'Paste was successfully created.' }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
50 format.json { render :json => @paste, :status => :created, :location => @paste }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
51 else
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
52 format.html { render :action => "new" }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
53 format.json { render :json => @paste.errors, :status => :unprocessable_entity }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
54 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
55 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
56 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
57
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
58 # PUT /pastes/1
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
59 # PUT /pastes/1.json
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
60 def update
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
61 @paste = Paste.find(params[:id])
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
62
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
63 respond_to do |format|
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
64 if @paste.update_attributes(params[:paste])
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
65 format.html { redirect_to @paste, :notice => 'Paste was successfully updated.' }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
66 format.json { head :no_content }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
67 else
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
68 format.html { render :action => "edit" }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
69 format.json { render :json => @paste.errors, :status => :unprocessable_entity }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
70 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
71 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
72 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
73
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
74 # DELETE /pastes/1
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
75 # DELETE /pastes/1.json
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
76 def destroy
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
77 @paste = Paste.find(params[:id])
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
78 @paste.destroy
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
79
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
80 respond_to do |format|
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
81 format.html { redirect_to pastes_url }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
82 format.json { head :no_content }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
83 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
84 end
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
85 end