Last active
August 29, 2015 14:10
-
-
Save ashaw/c006d711f4261892da94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TilesController < ApplicationController | |
around_filter :up_s3 | |
def tile_response(map) | |
respond_to do |format| | |
format.png { | |
send_data map.to_png, :content_type => Mime::Type.lookup_by_extension("png"), :disposition => "inline" | |
} | |
end | |
end | |
def up_s3 | |
path = Rails.application.routes.recognize_path(request.env['PATH_INFO']) | |
path_str = "APPSLUG/#{Rails.env}/#{path[:slug]}/#{path[:v]}/#{path[:x]}/#{path[:y]}/#{path[:z]}.png" | |
obj = S3BUCKET.objects["#{path_str}"] | |
if obj.exists? | |
send_data obj.read, :content_type => Mime::Type.lookup_by_extension("png"), :disposition => "inline" | |
else | |
obj.write yield.first, :acl => :public_read, :content_type => "image/png" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment