Created
November 13, 2008 15:54
-
-
Save diegorv/24469 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 | |
@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 [email protected]? | |
@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