views:

36

answers:

1

I have 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?

+2  A: 

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

bjg
I get a 404. I setup a map.resources :controller in routes.rb
tapioco123
How i do the same for tar.gz files?
tapioco123
I believe the MIME type you're looking for ".tar.gz" is "application/x-gzip" so just register another alias for that and you're good to go. Did you resolve your 404? If you run `rake routes` do you see the resource's paths and format rules?
bjg
if i use tar.gz i get a 404, for zip works. seems that the point between tar.gz it's the issue
tapioco123
yes, for sure the problem is in routes.rb that don't route .tar.gz
tapioco123
Perhaps try an explicit routing specification like this: `map.connect('files/*path.:format', :controller => 'my_controller', :action => 'my_action', :requirements => {:format => /(zip|tar.gz)/})`, obviously with your controller and action substituted
bjg