Created
November 13, 2008 14:14
-
-
Save diegorv/24439 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasteController < ApplicationController | |
before_filter :last_pastes | |
private | |
def last_pastes | |
@last_pastes = Paste.last_pastes | |
end | |
public | |
def show | |
begin | |
@paste = Paste.show(params[:id]) | |
rescue ActiveRecord::RecordNotFound | |
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]) | |
@paste.destroy | |
redirect_to :action => "index" | |
end | |
def download | |
@paste = Paste.download(params[:id]) | |
@file_name = @paste.id.to_s + ".txt" | |
send_data @paste.code, :type => "application/force-download", :filename => @file_name | |
end | |
def search | |
end | |
def about | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment