view app/controllers/pastes_controller.rb @ 10:56c17679105b

Moar pastes.
author Edho Arief <edho@myconan.net>
date Sun, 26 Aug 2012 11:59:55 -0700
parents 3a1f6c2e195d
children f3adcff48173
line wrap: on
line source

class PastesController < ApplicationController
  # GET /pastes/1
  # GET /pastes/1.json
  def show
    @paste = Paste.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.txt # show.html.erb
      format.json { render :json => @paste }
    end
  end

  # GET /pastes/new
  # GET /pastes/new.json
  def new
    @paste = Paste.new
    begin
      @paste.paste = Paste.find(params[:base]).paste
    rescue
      nil
    end

    respond_to do |format|
      format.html # new.html.erb
      format.json { render :json => @paste }
    end
  end

  # POST /pastes
  # POST /pastes.json
  def create
    @paste = Paste.new
    @paste.paste = params[:paste][:paste]
    @paste.ip = request.remote_ip

    respond_to do |format|
      if @paste.save
        format.html { redirect_to @paste, :notice => 'Paste was successfully created.' }
        format.json { render :json => @paste, :status => :created, :location => @paste }
      else
        format.html { render :action => "new" }
        format.json { render :json => @paste.errors, :status => :unprocessable_entity }
      end
    end
  end

end