OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / app / controllers / stories_controller.rb
index e13a7d3..3832ea5 100644 (file)
@@ -119,12 +119,16 @@ class StoriesController < ApplicationController
 
   def destroy
     @story = Story.edit(params[:id], @author)
-    Story.transaction do
-      @story.destroy_and_shorten
-    end
     respond_to do |format|
-      format.html { redirect_to story_path(@story.comic) }
-      format.json { head :ok }
+      if @story.destroy_and_shorten
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
+        format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
+        format.html { redirect_to story_path(@story) }
+        format.json { render json: @story.errors, status: :unprocessable_entity }
+      end
     end
   end
 end