diff app/controllers/pastes_controller.rb @ 265:6cca1ab53337

Infinitely better error messages and notice.
author edogawaconan <me@myconan.net>
date Wed, 16 Oct 2013 02:56:30 +0900
parents 16251b94eb6c
children 200488650a86
line wrap: on
line diff
--- a/app/controllers/pastes_controller.rb	Wed Oct 16 02:19:36 2013 +0900
+++ b/app/controllers/pastes_controller.rb	Wed Oct 16 02:56:30 2013 +0900
@@ -48,6 +48,7 @@
           format.html { redirect_to @paste, :notice => 'Paste was successfully created.' }
           format.json { render :json => @paste, :status => :created, :location => @paste }
         else
+          flash[:alert] = @paste.errors.full_messages.to_sentence
           format.html { render :action => "new" }
           format.json { render :json => @paste.errors, :status => :unprocessable_entity }
         end
@@ -65,14 +66,12 @@
 
   def destroy
     @paste = Paste.safe_find(params[:id])
-    if @paste.key == params[:paste][:key]
-      @paste.destroy
+    if @paste.safe_destroy(params[:paste][:key])
       expire_page :controller => 'pastes', :action => 'show', :id => @paste.id
-      flash[:notice] = "Paste ##{params[:id]} deleted"
-      redirect_to root_path
+      redirect_to root_path, :notice => "Paste ##{params[:id]} deleted"
     else
-      flash[:error] = 'Incorrect deletion key'
-      render :action => :show
+      flash[:alert] = @paste.errors.full_messages.to_sentence
+      render :show
     end
   end