OSDN Git Service

add comic story
[pettanr/pettanr.git] / app / controllers / stories_controller.rb
index 0765171..f6beb21 100644 (file)
@@ -99,17 +99,19 @@ class StoriesController < ApplicationController
   end
   
   def create
-    @story = Story.new 
-    @story.supply_default
-    @story.attributes = params[:story]
-    @story.overwrite
-    @comic = Comic.edit(@story.comic_id, @operators) if @story.comic_id
+    @story = Story.new
+    @story.supply_default 
+    jsn = nil
+    if params[:json]
+      jsn = JSON.parse_no_except(params[:json])
+    end
+    @prm = params[:story] || jsn
     
     respond_to do |format|
-      if @story.store @operators
+      if @story.store @prm, @operators
         flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
-        format.html { redirect_to play_story_path(@story, :page => @story.t.to_i + 1) }
-        format.json { render json: @story.to_json(Story.show_json_opt) }
+        format.html { redirect_to @story }
+        format.json { render json: @story.to_json(Story.show_json_opt), status: :created, location: @story }
       else
         flash[:notice] = I18n.t('flash.notice.not_created', :model => Story.model_name.human)
         format.html { render action: "new" }
@@ -120,13 +122,15 @@ class StoriesController < ApplicationController
   
   def update
     @story = Story.edit(params[:id], @operators)
-    ot = @story.t
-    @story.attributes = params[:story]
-    @story.overwrite
+    jsn = nil
+    if params[:json]
+      jsn = JSON.parse(params[:json])
+    end
+    @prm = params[:story] || jsn
     respond_to do |format|
-      if @story.store @operators, ot
+      if @story.store @prm, @operators
         flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
-        format.html { redirect_to play_story_path(@story, :page => @story.t.to_i + 1) }
+        format.html { redirect_to @story }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Story.model_name.human)
@@ -135,19 +139,20 @@ class StoriesController < ApplicationController
       end
     end
   end
-
+  
   def destroy
     @story = Story.edit(params[:id], @operators)
     respond_to do |format|
-      if @story.destroy_and_shorten
+      if @story.destroy_with_story_panel
         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
-        format.html { redirect_to comic_path(@story.comic)}
+        format.html { redirect_to '/home/stories' }
         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.html { redirect_to @story }
         format.json { render json: @story.errors, status: :unprocessable_entity }
       end
     end
   end
+  
 end