OSDN Git Service

dd6879e6d3e656af00965c0fdfea98e97628390f
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
1 class ResourcePicturesController < ApplicationController
2   before_filter :authenticate_author!, :only => [:index, :show]
3   before_filter :authenticate_admin!, :only => [:list, :browse]
4
5   # GET /resource_pictures
6   # GET /resource_pictures.json
7   def index
8     @resource_pictures = ResourcePicture.find(:all, 
9       :include => {:original_picture => [:artist, :license]}, :order => 'updated_at', :limit => 20
10     )
11
12     respond_to do |format|
13       format.html # index.html.erb
14       format.json { render :json => @resource_pictures.to_json(
15         :include => [:original_picture, :artist, :license]
16       ) }
17     end
18   end
19
20   # GET /resource_pictures/1
21   # GET /resource_pictures/1.json
22   def show
23     @resource_picture = ResourcePicture.find(params[:id])
24
25     respond_to do |format|
26       opt = {:type => @resource_picture.mime_type, :disposition=>"inline"}
27       format.png { send_data(@resource_picture.restore(params[:subdir]), opt ) }
28       format.gif { send_data(@resource_picture.restore(params[:subdir]), opt ) }
29       format.jpeg { send_data(@resource_picture.restore(params[:subdir]), opt ) }
30       format.html # show.html.erb
31       format.json { render json: @resource_picture}
32     end
33   end
34
35   def list
36     @resource_pictures = ResourcePicture.all
37
38     respond_to do |format|
39       format.html { render layout: 'system' }
40       format.json { render json: @resource_pictures }
41     end
42   end
43
44   def browse
45     @resource_picture = ResourcePicture.find(params[:id])
46
47     respond_to do |format|
48       format.html { render layout: 'system' }
49       format.json { render json: @resource_picture }
50     end
51   end
52
53 end