OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / app / controllers / panels_controller.rb
index c2bc788..7d5e4e6 100644 (file)
@@ -115,9 +115,15 @@ class PanelsController < ApplicationController
     @panel = Panel.edit(params[:id], @author)
     respond_to do |format|
       Panel.transaction do
-        @panel.destroy
-        format.html { redirect_to panels_url }
-        format.json { head :ok }
+        if @panel.destroy_with_elements
+          flash[:notice] = I18n.t('flash.notice.destroyed', :model => Panel.model_name.human)
+          format.html { redirect_to '/home/panel' }
+          format.json { head :ok }
+        else
+          flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Panel.model_name.human)
+          format.html { redirect_to @panel }
+          format.json { render json: @panel.errors, status: :unprocessable_entity }
+        end
       end
     end
   end