1 class SystemPicturesController < ApplicationController
2 before_filter :authenticate_admin!, :except => [:index, :show]
8 if (f = prm[:system_picture][:file]).respond_to?(:read)
10 @system_picture.width = 0
11 @system_picture.height = 0
12 @system_picture.ext = 'none'
13 @system_picture.filesize = 1.megabytes
15 img = Magick::Image.from_blob(f.read).shift
16 @system_picture.width = img.columns
17 @system_picture.height = img.rows
18 @system_picture.ext = img.format.downcase
19 @system_picture.filesize = f.size
22 dat = Base64.decode64(prm[:system_picture][:file].to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
23 img = Magick::Image.from_blob(dat).shift
24 @system_picture.width = img.columns
25 @system_picture.height = img.rows
26 @system_picture.ext = img.format.downcase
27 @system_picture.filesize = 1000
34 # GET /system_pictures
35 # GET /system_pictures.json
37 @system_pictures = SystemPicture.all
39 respond_to do |format|
40 format.html # index.html.erb
41 format.json { render json: @system_pictures }
45 # GET /system_pictures/1
46 # GET /system_pictures/1.json
48 @system_picture = SystemPicture.find(params[:id])
50 respond_to do |format|
51 opt = {:type => @system_picture.mime_type, :disposition=>"inline"}
52 format.png { send_data(@system_picture.restore, opt ) }
53 format.gif { send_data(@system_picture.restore, opt ) }
54 format.jpeg { send_data(@system_picture.restore, opt ) }
55 format.html # show.html.erb
56 format.json { render json: @system_picture}
60 # GET /system_pictures/new
61 # GET /system_pictures/new.json
63 @system_picture = SystemPicture.new
65 respond_to do |format|
66 format.html # new.html.erb
67 format.json { render json: @system_picture }
71 # GET /system_pictures/1/edit
73 @system_picture = SystemPicture.find(params[:id])
76 # POST /system_pictures
77 # POST /system_pictures.json
79 @system_picture = SystemPicture.new
80 img = set_image params
82 respond_to do |format|
83 SystemPicture.transaction do
84 if @system_picture.save
85 if @system_picture.store(img)
86 format.html { redirect_to @system_picture, notice: 'system picture was successfully created.' }
87 format.json { render json: @system_picture, status: :created, location: @system_picture }
89 format.html { redirect_to @system_picture, notice: 'Failed! system picture was NOT created.' }
90 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
93 format.html { render action: "new" }
94 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
100 # PUT /system_pictures/1
101 # PUT /system_pictures/1.json
103 @system_picture = SystemPicture.find(params[:id])
104 img = set_image params
106 respond_to do |format|
107 SystemPicture.transaction do
108 if @system_picture.save
109 if @system_picture.store(img)
110 format.html { redirect_to @system_picture, notice: 'System picture was successfully updated.' }
111 format.json { head :ok }
113 format.html { redirect_to @system_picture, notice: 'Failed! System picture was NOT created.' }
114 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
117 format.html { render action: "edit" }
118 format.json { render json: @system_picture.errors, status: :unprocessable_entity }
124 # DELETE /system_pictures/1
125 # DELETE /system_pictures/1.json
127 @system_picture = SystemPicture.find(params[:id])
128 SystemPicture.transaction do
129 @system_picture.destroy
133 respond_to do |format|
134 format.html { redirect_to system_pictures_url }
135 format.json { head :ok }