How can i add download functionality

Hello friends

i have to generate a text file when clicked on a button and when this
file got generated than i have to show a download dialog box so that
user can download this text file on his computer, can any body gives any
snippet of code or any idea how can i add this download functionality.

Thanks

your download dialog should simply link to an action that uses send_file
to send the text file:

send_file(File.join(FILE_PATH, file_name), :filename => ‘something.txt’,
:disposition => ‘attachment’, :type => ‘text/plain’

Thorsten M. wrote:

your download dialog should simply link to an action that uses send_file
to send the text file:

send_file(File.join(FILE_PATH, file_name), :filename => ‘something.txt’,
:disposition => ‘attachment’, :type => ‘text/plain’

Hello friend,
Thanks for your help but it is not working for me , instead of the
download dialog box its just showing me the content of the text file.
can u give me any idea why this is happening… ?

Thanks

Hello friend,
Thanks for your help but it is not working for me , instead of thedownloaddialogbox its just showing me the content of the text file.
can u give me any idea why this is happening… ?

You can also use send_data(). Instead of generating the output and
then writing it to a file and then attempting to send that file, you
can just generate the output and send it, skipping the file part:

data = “A String you generated somehow”

send_data( data, :filename => ‘filename.txt’ )