Reputation: 8757
I have a page that lists records based on the parameters given in the search filter. I need to give a download link, wherein the current records on the page are written to a file and given as a link to be downloaded.
So to put it simple, how do I give the latest records found based on the search parameters as a download link ?
P.S : I'm using the send_file method.
Upvotes: 1
Views: 73
Reputation: 261
You could link to the download action using a custom :format merged with the query params. Something like this:
<%= link_to "Download", posts_path(params.except("action", "controller").merge(:format => "csv")) %>
Not the cleanest example but hopefully you get the idea.
Upvotes: 1
Reputation: 6068
You can use CSV writer to generate the required file and give a download link to the file for users.
Thanks, Anubhaw
Upvotes: 0