OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
index 7054277..3fd04cb 100644 (file)
@@ -1,8 +1,9 @@
 class ResourcePicturesController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
-  before_filter :authenticate_user!, :only => [:index, :show, :credit, :new, :create, :update]
+  before_filter :authenticate_user!, :only => [:index, :show, :credit, :new, :create, :update, :destroy]
+  before_filter :authenticate_author, :only => [:index, :show, :credit, :new, :create, :update, :destroy]
   before_filter :authenticate_admin!, :only => [:list, :browse]
-  before_filter :authenticate_artist, :only => [:new, :create]
+  before_filter :authenticate_artist, :only => [:new, :create, :destroy]
 
   # GET /resource_pictures
   # GET /resource_pictures.json
@@ -86,6 +87,20 @@ class ResourcePicturesController < ApplicationController
     end
   end
   
+  def destroy
+    @resource_picture = ResourcePicture.edit(params[:id], @artist)
+
+    respond_to do |format|
+      if @resource_picture.unpublish
+        format.html { redirect_to resource_pictures_path }
+        format.json { head :ok }
+      else
+        format.html { redirect_to resource_picture_path(@resource_picture) }
+        format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+  
   def count
     @resource_picture = {:count => ResourcePicture.visible_count}
     respond_to do |format|