开发者

Enabling users to download current data on the page

开发者 https://www.devze.com 2023-01-22 20:33 出处:网络
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 t

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

0

精彩评论

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