OSDN Git Service

t#30169:show, index action create all resource
[pettanr/pettanr.git] / app / controllers / system_pictures_controller.rb
1 class SystemPicturesController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   before_filter :authenticate_user!, :only => [:index, :show]
4   before_filter :authenticate_author, :only => [:index, :show]
5   before_filter :authenticate_admin!, :only => [:list, :browse, :new, :create]
6
7   # GET /system_pictures
8   # GET /system_pictures.json
9   def index
10     @page = SystemPicture.page params[:page]
11     @page_size = SystemPicture.page_size params[:page_size]
12     @system_pictures = SystemPicture.list(@page, @page_size)
13
14     respond_to do |format|
15       format.html # index.html.erb
16       format.json { render json: @system_pictures.to_json(SystemPicture.list_json_opt) }
17     end
18   end
19
20   # GET /system_pictures/1
21   # GET /system_pictures/1.json
22   def show
23     @system_picture = SystemPicture.show(params[:id], @author)
24     
25     respond_to do |format|
26       opt = {:type => @system_picture.mime_type, :disposition=>"inline"}
27       format.png { send_data(@system_picture.restore, opt ) }
28       format.gif { send_data(@system_picture.restore, opt ) }
29       format.jpeg { send_data(@system_picture.restore, opt ) }
30       format.html # show.html.erb
31       format.json { render json: @system_picture.to_json(SystemPicture.show_json_opt)}
32     end
33   end
34
35   def list
36     @system_pictures = SystemPicture.all
37
38     respond_to do |format|
39       format.html { render layout: 'system' }
40       format.json { render json: @system_pictures }
41     end
42   end
43
44   def browse
45     @system_picture = SystemPicture.find(params[:id])
46
47     respond_to do |format|
48       format.html { render layout: 'system' }
49       format.json { render json: @system_picture}
50     end
51   end
52
53 end