Enabling users to download current data on the page
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.
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.
You can use CSV writer to generate the required file and give a download link to the file for users.
Thanks, Anubhaw
精彩评论