Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. However, I need to sometimes return this file as an XML plist file and sometimes as a binary plist file.

I thought that URLs composed like /resources.xml.plist and /resources.binary.plist would be a nice way to distinguish between them. I'd then need to add a MIME type for binary.plist and one for xml.plist and then somehow respond_to these formats.

Does any one know how this might be accomplished and/or have ideas for a nicer approach?

like image 961
Bo Jeanes Avatar asked Jan 21 '23 11:01

Bo Jeanes


1 Answers

Take a look at tutorial "Using custom mime types".


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
like image 101
antage Avatar answered Mar 15 '23 01:03

antage