Mercurial > zeropaste
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 1:49c0949ee47e | 2:42de15334db1 | 
|---|---|
| 1 class PastesController < ApplicationController | |
| 2 # GET /pastes | |
| 3 # GET /pastes.json | |
| 4 def index | |
| 5 @pastes = Paste.all | |
| 6 | |
| 7 respond_to do |format| | |
| 8 format.html # index.html.erb | |
| 9 format.json { render :json => @pastes } | |
| 10 end | |
| 11 end | |
| 12 | |
| 13 # GET /pastes/1 | |
| 14 # GET /pastes/1.json | |
| 15 def show | |
| 16 @paste = Paste.find(params[:id]) | |
| 17 | |
| 18 respond_to do |format| | |
| 19 format.html # show.html.erb | |
| 20 format.json { render :json => @paste } | |
| 21 end | |
| 22 end | |
| 23 | |
| 24 # GET /pastes/new | |
| 25 # GET /pastes/new.json | |
| 26 def new | |
| 27 @paste = Paste.new | |
| 28 | |
| 29 respond_to do |format| | |
| 30 format.html # new.html.erb | |
| 31 format.json { render :json => @paste } | |
| 32 end | |
| 33 end | |
| 34 | |
| 35 # GET /pastes/1/edit | |
| 36 def edit | |
| 37 @paste = Paste.find(params[:id]) | |
| 38 end | |
| 39 | |
| 40 # POST /pastes | |
| 41 # POST /pastes.json | |
| 42 def create | |
| 43 @paste = Paste.new | |
| 44 @paste.paste = params[:paste][:paste] | |
| 45 @paste.ip = request.remote_ip | |
| 46 | |
| 47 respond_to do |format| | |
| 48 if @paste.save | |
| 49 format.html { redirect_to @paste, :notice => 'Paste was successfully created.' } | |
| 50 format.json { render :json => @paste, :status => :created, :location => @paste } | |
| 51 else | |
| 52 format.html { render :action => "new" } | |
| 53 format.json { render :json => @paste.errors, :status => :unprocessable_entity } | |
| 54 end | |
| 55 end | |
| 56 end | |
| 57 | |
| 58 # PUT /pastes/1 | |
| 59 # PUT /pastes/1.json | |
| 60 def update | |
| 61 @paste = Paste.find(params[:id]) | |
| 62 | |
| 63 respond_to do |format| | |
| 64 if @paste.update_attributes(params[:paste]) | |
| 65 format.html { redirect_to @paste, :notice => 'Paste was successfully updated.' } | |
| 66 format.json { head :no_content } | |
| 67 else | |
| 68 format.html { render :action => "edit" } | |
| 69 format.json { render :json => @paste.errors, :status => :unprocessable_entity } | |
| 70 end | |
| 71 end | |
| 72 end | |
| 73 | |
| 74 # DELETE /pastes/1 | |
| 75 # DELETE /pastes/1.json | |
| 76 def destroy | |
| 77 @paste = Paste.find(params[:id]) | |
| 78 @paste.destroy | |
| 79 | |
| 80 respond_to do |format| | |
| 81 format.html { redirect_to pastes_url } | |
| 82 format.json { head :no_content } | |
| 83 end | |
| 84 end | |
| 85 end | 
