1 class SystemPicturesController < ApplicationController
2 before_filter :authenticate_user!, :only => [:index, :show]
3 before_filter :authenticate_admin!, :only => [:list, :browse, :create, :update, :destroy]
9 if (f = prm[:system_picture][:file]).respond_to?(:read)
11 @system_picture.width = 0
12 @system_picture.height = 0
13 @system_picture.ext = 'none'
14 @system_picture.filesize = 1.megabytes
16 img = Magick::Image.from_blob(f.read).shift
17 @system_picture.width = img.columns
18 @system_picture.height = img.rows
19 @system_picture.ext = img.format.downcase
20 @system_picture.filesize = f.size
23 dat = Base64.decode64(prm[:system_picture][:file].to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
24 img = Magick::Image.from_blob(dat).shift
25 @system_picture.width = img.columns
26 @system_picture.height = img.rows
27 @system_picture.ext = img.format.downcase
28 @system_picture.filesize = 1000
35 # GET /system_pictures
36 # GET /system_pictures.json
38 @system_pictures = SystemPicture.all
40 respond_to do |format|
41 format.html # index.html.erb
42 format.json { render json: @system_pictures }
46 # GET /system_pictures/1
47 # GET /system_pictures/1.json
49 @system_picture = SystemPicture.find(params[:id])
51 respond_to do |format|
52 opt = {:type => @system_picture.mime_type, :disposition=>"inline"}
53 format.png { send_data(@system_picture.restore, opt ) }
54 format.gif { send_data(@system_picture.restore, opt ) }
55 format.jpeg { send_data(@system_picture.restore, opt ) }
56 format.html # show.html.erb
57 format.json { render json: @system_picture}
62 @system_pictures = SystemPicture.all
64 respond_to do |format|
65 format.html { render layout: 'system' }
66 format.json { render json: @system_pictures }
71 @system_picture = SystemPicture.find(params[:id])
73 respond_to do |format|
74 format.html { render layout: 'system' }
75 format.json { render json: @system_picture}
80 # POST /system_pictures
81 # POST /system_pictures.json
83 @system_picture = SystemPicture.new
84 img = set_image params
86 respond_to do |format|
87 SystemPicture.transaction do
88 if @system_picture.save
89 if @system_picture.store(img)
90 format.html { redirect_to @system_picture, notice: 'system picture was successfully created.' }
91 format.json { render json: @system_picture, status: :created, location: @system_picture }
93 format.html { redirect_to @system_picture, notice: 'Failed! system picture was NOT created.' }
94 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
97 format.html { render action: "new" }
98 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
104 # PUT /system_pictures/1
105 # PUT /system_pictures/1.json
107 @system_picture = SystemPicture.find(params[:id])
108 img = set_image params
110 respond_to do |format|
111 SystemPicture.transaction do
112 if @system_picture.save
113 if @system_picture.store(img)
114 format.html { redirect_to @system_picture, notice: 'System picture was successfully updated.' }
115 format.json { head :ok }
117 format.html { redirect_to @system_picture, notice: 'Failed! System picture was NOT created.' }
118 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
121 format.html { render action: "edit" }
122 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
128 # DELETE /system_pictures/1
129 # DELETE /system_pictures/1.json
131 @system_picture = SystemPicture.find(params[:id])
132 SystemPicture.transaction do
133 @system_picture.destroy
137 respond_to do |format|
138 format.html { redirect_to system_pictures_url }
139 format.json { head :ok }