Rails - 渲染模板和 zip

发布于 2024-11-01 15:42:41 字数 519 浏览 0 评论 0原文

我正在尝试在 Rails 中构建一个 KML 文件,我已经成功完成了,但现在我还想提供一个 KMZ 格式,它将呈现 index.kml 文件并将其压缩。这就是我被难住的地方。我已更新 MIME 类型如下。

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

这是我的格式块

def index
    @map_items = Items.all
    respond_with(@map_items) do |format|  
      format.kml 
      format.kmz { NOT SURE WHAT IS BEST TO DO }
      format.georss 
    end
  end

任何帮助将不胜感激。谢谢!

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.kml 
      format.kmz { NOT SURE WHAT IS BEST TO DO }
      format.georss 
    end
  end

ANy help would be much appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帝王念 2024-11-08 15:42:41

我找到了一种通过延迟工作来做到这一点的方法。每次更新或创建点时,我都会触发 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文