开发者

rails - Render template and zip

I'm trying to build a KML file in Rails, which I have done successfully, but now I want to provide a KMZ format as well which would render the index.kml file and zip it. Here is where I get stumped. I have updated the MIME Types as follows.

Mime::Type.register_alias "application/vnd.google-earth.kml+xml", :kml
Mime::Type.register_alias "application/vnd.google-earth.kmz", :kmz

Here is my format block

def index
    @map_items = Items.all
    respond_with(@map_items) do |format|  
      format.km开发者_开发技巧l 
      format.kmz { NOT SURE WHAT IS BEST TO DO }
      format.georss 
    end
  end

ANy help would be much appreciated. Thanks!


I figured out a way to do this with Delayed Job. Every time the points are updated or created I fire off the MapOverlayJob.

class MapsController < ApplicationController

  def overlay
    @points = Points.all
    return render_to_string("overlay.kml")
  end

end


class MapOverlayJob

  def initialize
    @s3_filename ||= "maps/overlay.kmz"
    @zip_filename ||= "overlay.kml"
  end

  def perform
    AWS::S3::S3Object.store(@s3_filename, 
                            build_kmz_file, 
                            S3_BUCKET, 
                            :access => S3_ACL, 
                            :content_type => Mime::KMZ)
  end

  private
    def build_kmz_file
      Zippy.new(@zip_filename => MapsController.new.overlay).data
    end

end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜