0

In my Rails 4.2 app I have a simple controller action that downloads a ZIP file:

class PresskitController < ApplicationController

  def download
    respond_to do |format|      
      format.zip do   
        send_data(Presskit.new, :filename => "presskit.zip")
      end
    end
  end

end

This URL works great: http://www.myapp.com/presskit.zip

Is there a way to make this URL work without the extension as well? So that clicking on http://www.myapp.com/presskit would also trigger the download?

Thanks for any help.

Tintin81
  • 9,821
  • 20
  • 85
  • 178

1 Answers1

1

Just use the send_data for your action? as you don't care about the format

class PresskitController < ApplicationController
  def download
    send_data(Presskit.new, :filename => "presskit.zip")
  end
end
siegy22
  • 4,295
  • 3
  • 25
  • 43
  • You are right. I just had to add `type: "application/zip"` to that. I hope Arup won't mind if I mark this answer as the correct one. Even though he was a little faster :-) – Tintin81 Aug 04 '16 at 11:14
  • 1
    I think he doesn't mind about the reputation (he's got 78'000). – siegy22 Aug 04 '16 at 11:33