Chaoyu
Chaoyu

Reputation: 842

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.

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 .

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. Any suggestion would be greatly appreciated. Thanks!

Upvotes: 8

Views: 9353

Answers (1)

jdoe
jdoe

Reputation: 15781

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

Documentation Here

Upvotes: 29

Related Questions