view app/controllers/pastes_controller.rb @ 83:ae360c3b0bb0

Disable explain when using jruby because it's not supported. The patch for this support exist but for some reason still not included in latest release of the jdbc adapter. Reference: https://github.com/jruby/activerecord-jdbc-adapter/pull/206
author Edho Arief <edho@myconan.net>
date Mon, 15 Oct 2012 03:45:18 -0700
parents 2fb80ca710e0
children 0f206bd4924f
line wrap: on
line source

class PastesController < ApplicationController
  caches_page :show

  # GET /1
  # GET /1.txt
  def show
    id = params[:id].to_i
    if id.to_s != params[:id]
      redirect_to paste_path(id)
      return
    end
    @paste = Paste.find(params[:id])

    expires_in 1.year, :public => true
    respond_to do |format|
      format.html # show.html.erb
      format.txt # show.txt.erb
    end
  end

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

    respond_to do |format|
      format.html # new.html.erb
    end
  end

  # POST /
  # POST /pastes.json
  # POST /pastes.txt
  def create
    @paste = Paste.new
    if params[:paste] and not params[:paste][:paste].blank?
      @paste.paste = params[:paste][:paste]
      @paste.ip = request.remote_ip
    end

    begin
      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
        format.txt
      end
    rescue ActiveRecord::RecordNotUnique
      redirect_to paste_path(Paste.where(:ip => @paste.ip, :paste_hash => @paste.paste_hash).first)
    end
  end

end