简体   繁体   English

如何从String生成文本文件以便在Ruby on Rails中下载

[英]How to generate a text file from a String for download in Ruby on Rails

I'm building a website using Rails and I have a Model with some text type value store in MySQL database, I need to provide a download link for my users to download a "*.txt" file which contains those texts. 我正在使用Rails构建一个网站,我在MySQL数据库中有一个带有一些文本类型值存储的模型,我需要为我的用户提供下载链接以下载包含这些文本的“* .txt”文件。

what I've tried is to use render :text => my_text but it's kind of ugly and the browser can't start a download . 我试过的是使用render :text => my_text但它有点难看,浏览器无法启动下载。

Not I'm trying to use CarrierWave and mount a output_file to my model , I want to build a method to generate a file from its text value. 不是我正在尝试使用CarrierWave并将output_file挂载到我的模型,我想构建一个方法来从其文本值生成文件。 Any suggestion would be greatly appreciated. 任何建议将不胜感激。 Thanks! 谢谢!

send_data 'text to send', :filename => 'some.txt'

文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM