Mercurial > zeropaste
comparison app/controllers/pastes_controller.rb @ 189:b4b7a29b70f6
Initial work for paste deletion.
| author | Edho Arief <edho@myconan.net> |
|---|---|
| date | Sat, 23 Feb 2013 14:01:22 +0900 |
| parents | fc234f8cf3d9 |
| children | d4682cea8e58 |
comparison
equal
deleted
inserted
replaced
| 188:45ec309a3fa8 | 189:b4b7a29b70f6 |
|---|---|
| 19 end | 19 end |
| 20 | 20 |
| 21 # GET / | 21 # GET / |
| 22 def new | 22 def new |
| 23 @paste = Paste.new | 23 @paste = Paste.new |
| 24 @paste.set_paste_key | |
| 24 begin | 25 begin |
| 25 @paste.paste = Paste.find(params[:base]).paste | 26 @paste.paste = Paste.find(params[:base]).paste |
| 26 rescue | 27 rescue |
| 27 end | 28 end |
| 28 | 29 |
| 45 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste][:paste_gzip_base64]))).read | 46 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste][:paste_gzip_base64]))).read |
| 46 end | 47 end |
| 47 unless params[:paste][:paste].blank? | 48 unless params[:paste][:paste].blank? |
| 48 @paste.paste = params[:paste][:paste] | 49 @paste.paste = params[:paste][:paste] |
| 49 end | 50 end |
| 51 if params[:paste][:key] | |
| 52 @paste.key = params[:paste][:key] | |
| 53 end | |
| 50 end | 54 end |
| 51 | 55 |
| 52 begin | 56 begin |
| 53 respond_to do |format| | 57 respond_to do |format| |
| 54 if @paste.save | 58 if @paste.save |
| 69 format.txt | 73 format.txt |
| 70 end | 74 end |
| 71 end | 75 end |
| 72 end | 76 end |
| 73 | 77 |
| 78 def destroy | |
| 79 @paste = Paste.find(params[:id].to_i) | |
| 80 if @paste.key == params[:paste][:key] | |
| 81 @paste.destroy | |
| 82 flash[:notice] = "Paste ##{params[:id]} deleted" | |
| 83 redirect_to root_path | |
| 84 else | |
| 85 render :action => :show | |
| 86 end | |
| 87 end | |
| 88 | |
| 74 end | 89 end |
