OSDN Git Service

t#30328:create op import ...and pull
[pettanr/pettanr.git] / app / controllers / stories_controller.rb
index 37c196a..3832ea5 100644 (file)
@@ -62,9 +62,6 @@ class StoriesController < ApplicationController
     end
   end
   
-  # GET /stories/new
-  # GET /stories/new.js
-  # GET /stories/new.json
   def new
     @story = Story.new 
     @story.supply_default
@@ -75,8 +72,6 @@ class StoriesController < ApplicationController
     end
   end
 
-  # GET /stories/1/edit
-  # GET /stories/1.js/edit
   def edit
     @story = Story.edit(params[:id], @author)
     respond_to do |format|
@@ -85,18 +80,17 @@ class StoriesController < ApplicationController
     end
   end
 
-  # POST /stories
-  # POST /stories.json
   def create
     @story = Story.new 
     @story.supply_default
     @story.attributes = params[:story]
     @story.overwrite @author
-    @comic = Comic.edit(@story.comic_id, @author)
-    @panel = Panel.show(@story.panel_id, @author)
+    @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
+    @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
     
     respond_to do |format|
       if @story.store
+        flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
         format.html { redirect_to action: :comic, id: @story.comic_id }
         format.json { render json: @story.story_as_json(@author) }
       else
@@ -106,8 +100,6 @@ class StoriesController < ApplicationController
     end
   end
   
-  # PUT /stories/1
-  # PUT /stories/1.json
   def update
     @story = Story.edit(params[:id], @author)
     ot = @story.t
@@ -115,6 +107,7 @@ class StoriesController < ApplicationController
     @story.overwrite @author
     respond_to do |format|
       if @story.store ot
+        flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
         format.html { redirect_to action: :comic, id: @story.comic_id }
         format.json { head :ok }
       else
@@ -124,17 +117,18 @@ class StoriesController < ApplicationController
     end
   end
 
-  # DELETE /stories/1
-  # DELETE /stories/1.js
-  # DELETE /stories/1.json
   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