OSDN Git Service

Mobile Deviceを利用せずに、JPMobileを利用するよう修正(社内ブランチよりマージ)
[elecoma/elecoma.git] / app / controllers / image_resource_controller.rb
1 class ImageResourceController < BaseController
2
3   #caches_page :show
4   def show
5     if params[:filename] 
6       @res = ImageResource.find_by_name(params[:filename])
7     end
8     if params[:id]
9       @res ||= ImageResource.find_by_id(params[:id])
10     end
11     raise ActiveRecord::RecordNotFound unless @res
12     if request.mobile?
13       if params[:width].present? || params[:height].present?
14         width, height = [params[:width].to_i, params[:height].to_i]
15       else
16         width, height = request.mobile.display.width, request.mobile.display.height
17       end
18       send_file @res, @res.scaled_image(width, height)
19     else
20       send_file @res, @res.view
21     end
22   end
23
24   def thumbnail
25   end
26
27   private
28   
29   def send_file(res, data)
30     raise ActiveRecord::RecordNotFound unless res
31     raise ActiveRecord::RecordNotFound unless data
32     content_type = res.content_type
33     if request.mobile?
34       content_type.gsub!(/pjpeg/, "jpeg")
35     end
36     send_data(data, :type => content_type, :disposition => 'inline')
37   end
38 end