开发者

Custom extension in rails routes

开发者 https://www.devze.com 2023-01-09 09:03 出处:网络
I have开发者_StackOverflow中文版 to serve rails generated zip files. For example from the following REST route:

I have开发者_StackOverflow中文版 to serve rails generated zip files. For example from the following REST route: http://foo.com/controller/show/filename.zip

How i need to map routes.rb to allow the routing of zip files (instead searching for static files in /public) to my controller?


If you've set up your routes using the map.resources in config/routes.rb then I think you already have the routes you want. What I think you need is to add a custom mime type to you controller like this:

Mime::Type.register_alias "application/zip", :zip

Then

respond_to do |format|
  format.zip { ... }
end

Also available in request.format

0

精彩评论

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

关注公众号