OSDN Git Service

fix: rp update faild
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
index a0847fe..6850873 100644 (file)
@@ -1,33 +1,34 @@
 class ResourcePicturesController < ApplicationController
   if Manifest.manifest.magic_numbers['run_mode'] == 0
-    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
-    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
+    before_action :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_action :authenticate_artist, :only => [:new, :create, :update, :destroy]
   else
-    before_filter :authenticate_resource_reader, :only => [
-      :index, :show, :credit, :by_license_group, :by_license, :by_artist, :count, :count_by_license_group, :count_by_license, :count_by_artist
+    before_action :authenticate_resource_reader, :only => [
+      :index, :show, :credit, 
+      :by_original_picture, :by_license_group, :by_license, :by_artist, :search
     ]
-    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
-    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
-  end
-
-  def self.model
-    ResourcePicture
+    before_action :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_action :authenticate_artist, :only => [:new, :create, :update, :destroy]
   end
   
   def index
     filer_list
   end
   
+  def by_original_picture
+    filer_list param: params[:id]
+  end
+  
   def by_license_group
-    filer_list
+    filer_list param: params[:id]
   end
   
   def by_license
-    filer_list
+    filer_list param: params[:id]
   end
   
   def by_artist
-    filer_list
+    filer_list param: params[:id]
   end
   
   def show_html_format format
@@ -57,22 +58,6 @@ class ResourcePicturesController < ApplicationController
     end
   end
   
-  def count
-    list_count
-  end
-  
-  def count_by_license_group
-    list_count
-  end
-  
-  def count_by_license
-    list_count
-  end
-  
-  def count_by_artist
-    list_count
-  end
-  
   def new
     # use @item, @original_picture
     respond_to do |format|
@@ -87,12 +72,13 @@ class ResourcePicturesController < ApplicationController
     if params[:json]
       jsn = JSON.parse_no_except(params[:json])
     end
+    @item = @original_picture.resource_picture || ResourcePicture.new
     @prm = if params[:resource_picture] == nil or params[:resource_picture].empty?
-       jsn
+      jsn
     else
-       params[:resource_picture]
+      @item.permit_params(params)
     end
-    @item = @original_picture.resource_picture || ResourcePicture.new
+    @prm.delete 'id'
     @item.attributes = @prm
     @item.overwrite @original_picture
     @item.boosts 'post'
@@ -109,17 +95,9 @@ class ResourcePicturesController < ApplicationController
   end
   
   def destroy
-    @resource_picture = ResourcePicture.edit(params[:id], @operators)
-
-    respond_to do |format|
-      if @resource_picture.unpublish
-        format.html { redirect_to :controller => '/home', :action => :resource_pictures }
-        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
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy_by 'unpublish', '/home/' + @item.path_name
   end
   
   def count
@@ -129,4 +107,13 @@ class ResourcePicturesController < ApplicationController
     end
   end
   
+  def search
+    @resource_pictures = ResourcePicture.find_by_md5(params[:md5])
+    
+    respond_to do |format|
+      format.html
+      format.json { render json: @resource_pictures.to_json }
+    end
+  end
+  
 end