OSDN Git Service

fix: op upload and destroy
[pettanr/pettanr.git] / app / controllers / scroll_panels_controller.rb
index c11046a..ffcee61 100644 (file)
@@ -4,15 +4,11 @@ class ScrollPanelsController < ApplicationController
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
     before_filter :authenticate_reader, :only => [
-      :index, :show, :by_panel, :by_scroll, :by_author, :count, :count_by_panel, :count_by_scroll, :count_by_author
+      :index, :show, :by_panel, :by_scroll, :by_author
     ]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
-
-  def self.model
-    ScrollPanel
-  end
   
   def index
     filer_list
@@ -34,26 +30,10 @@ class ScrollPanelsController < ApplicationController
     set_show
     respond_to do |format|
       show_prof_format format
-      format.json { render json: @item.scroll_panel_as_json(@operators.author) }
+      format.json { render json: @item.to_json }
     end
   end
   
-  def count
-    list_count
-  end
-  
-  def count_by_panel
-    list_count
-  end
-  
-  def count_by_scroll
-    list_count
-  end
-  
-  def count_by_author
-    list_count
-  end
-  
   def new
     form_new
   end
@@ -63,7 +43,7 @@ class ScrollPanelsController < ApplicationController
   end
   
   def create
-    @my_model_class = self.class.model
+    set_model
     @item = @my_model_class.new
     @item.supply_default
     @item.attributes = params[@item.item_name]
@@ -75,7 +55,7 @@ class ScrollPanelsController < ApplicationController
   end
   
   def update
-    @my_model_class = self.class.model
+    set_model
     @item = @my_model_class.edit(params[:id], @operators)
     ot = @item.t
     @item.attributes = params[@item.item_name]
@@ -89,18 +69,10 @@ class ScrollPanelsController < ApplicationController
   end
   
   def destroy
-    @scroll_panel = ScrollPanel.edit(params[:id], @operators)
-    @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
-    respond_to do |format|
-      if @scroll_panel.destroy_and_shorten
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)
-        format.html { redirect_to play_scroll_path(@scroll) }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ScrollPanel.model_name.human)
-        format.html { redirect_to scroll_panel_path(@scroll_panel) }
-        format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+    render_destroy '/home/' + play_scroll_path(@item)
   end
+  
 end