Skip to content

Instantly share code, notes, and snippets.

@diegorv
Created November 13, 2008 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegorv/24469 to your computer and use it in GitHub Desktop.
Save diegorv/24469 to your computer and use it in GitHub Desktop.
class PasteController < ApplicationController
before_filter :last_pastes
private
def last_pastes
@last_pastes = Paste.last_pastes
end
public
def show
@paste = Paste.show(params[:id])
if @paste.nil?
redirect_to :action => "index"
end
end
def save
require "digest"
@paste = Paste.new(params[:paste])
@paste.pkey = Digest::MD5.hexdigest("#{Time.now}#{rand}")
@paste.ip = request.remote_ip
if @paste.save
flash[:notice] = 'Poste salvo com sucesso!.'
flash[:poste_key] = @paste.pkey
redirect_to :action => "show", :id => @paste.id
else
render :action => "new"
end
end
def delete
@paste = Paste.find_by_pkey(params[:id])
if !@paste.nil?
@paste.destroy
end
redirect_to :action => "index"
end
def download
@paste = Paste.download(params[:id])
if @paste.nil?
redirect_to :action => "index"
else
@file_name = @paste.id.to_s + ".txt"
send_data(@paste.code, :type => "application/force-download", :filename => @file_name)
end
end
def search
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment