OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
index b68a578..d57a084 100644 (file)
@@ -15,8 +15,6 @@ class ComicsController < ApplicationController
     end
   end
   
-  # GET /comics
-  # GET /comics.json
   def index
     @page = Comic.page params[:page]
     @page_size = Comic.page_size params[:page_size]
@@ -27,8 +25,6 @@ class ComicsController < ApplicationController
     end
   end
 
-  # GET /comics/1
-  # GET /comics/1.json
   def show
     @comic = Comic.show(params[:id], @author)
 
@@ -63,8 +59,6 @@ class ComicsController < ApplicationController
     end
   end
   
-  # GET /comics/new
-  # GET /comics/new.js
   def new
     @comic = Comic.new
     @comic.supply_default
@@ -75,8 +69,6 @@ class ComicsController < ApplicationController
     end
   end
 
-  # GET /comics/1/edit
-  # GET /comics/1.js/edit
   def edit
     @comic = Comic.edit(params[:id], @author)
     respond_to do |format|
@@ -85,8 +77,6 @@ class ComicsController < ApplicationController
     end
   end
 
-  # POST /comics
-  # POST /comics.json
   def create
     @comic = Comic.new
     @comic.supply_default 
@@ -105,8 +95,6 @@ class ComicsController < ApplicationController
     end
   end
 
-  # PUT /comics/1
-  # PUT /comics/1.json
   def update
     @comic = Comic.edit(params[:id], @author)
     @comic.attributes = params[:comic]
@@ -123,14 +111,18 @@ class ComicsController < ApplicationController
     end
   end
 
-  # DELETE /comics/1
-  # DELETE /comics/1.json
   def destroy
     @comic = Comic.edit(params[:id], @author)
-    @comic.destroy
     respond_to do |format|
-      format.html { redirect_to comics_url }
-      format.json { head :ok }
+      if @comic.destroy_with_story
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
+        format.html { redirect_to '/home/comic' }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
+        format.html { redirect_to @comic }
+        format.json { render json: @comic.errors, status: :unprocessable_entity }
+      end
     end
   end
 end