简体   繁体   English

rails controller respond_to格式有两个扩展名(例如tar.gz)

[英]rails controller respond_to format with two extensions (e.g. tar.gz)

Is there a mechanism or accepted approach for responding to requests that have a more complicated format extension? 是否有一种机制或接受的方法来响应具有更复杂格式扩展的请求?

My specific scenario involves returning a plist file. 我的具体方案涉及返回一个plist文件。 However, I need to sometimes return this file as an XML plist file and sometimes as a binary plist file. 但是,我有时需要将此文件作为XML plist文件返回,有时作为二进制plist文件。

I thought that URLs composed like /resources.xml.plist and /resources.binary.plist would be a nice way to distinguish between them. 我认为像/resources.xml.plist/resources.binary.plist组成的URL将是区分它们的好方法。 I'd then need to add a MIME type for binary.plist and one for xml.plist and then somehow respond_to these formats. 然后,我需要为binary.plist添加一个MIME类型,为binary.plist添加一个MIME类型,然后以某种方式xml.plist这些格式。

Does any one know how this might be accomplished and/or have ideas for a nicer approach? 有没有人知道如何实现这一目标和/或有更好的方法的想法?

Take a look at tutorial " Using custom mime types ". 看一下教程“ 使用自定义mime类型 ”。


Mime::Type.register "application/xml", :plist_xml, [], ["xml.plist"]
Mime::Type.register "application/octet-stream", :plist_binary, [], ["binary.plist"]

...

respond_to do |format|
  format.plist_xml { ... }
  format.plist_binary { ... }
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM