use send_data for downloadable not working in Rails 5.0.0?

652 views
Skip to first unread message

Liz Huang

unread,
Aug 8, 2016, 2:25:44 PM8/8/16
to Ruby on Rails: Talk


Hi, 

Recently I just upgrade rails from 4.2.0 to 5.0.0, wonder what I need to do to
make send_data downloadable file working again? Now the data displayed in
page instead of downloadable file as before?

Thanks!
Liz

Colin Law

unread,
Aug 8, 2016, 4:15:44 PM8/8/16
to Ruby on Rails: Talk
You need to post the bit of code that is failing so we can see what
you are doing. We are not telepathic. Not large chunks of code just
the bit that is failing. Tell us what you expect that bit of code to
do and what it actually does.

Colin

Liz Huang

unread,
Aug 8, 2016, 4:40:21 PM8/8/16
to Ruby on Rails: Talk


THe part of code is:

  def downloadCSV
    require 'csv'
    @ary = session[:ary]
    csv_string= CSV.generate do |csv|
        @ary.each do |t|
        csv << [t]
        end             
    end           

    send_data csv_string,
    type: 'text/csv; charset=iso-8859-1; header=present',
    disposition: 'attachment', filename: 'rannumgenerator.csv'

  end

The web applet link is:


You can enter 1000 for N and 13 for C, click compute, get a result page,
which has 

Download: CSV | Excel

the code above is used for downloading CSV file after click CSV, which works
in rails 4.2.0, now instead of showing the download dialog, all numbers displayed 
in the page.

Thanks!
Liz

Liz Huang

unread,
Aug 10, 2016, 9:53:19 AM8/10/16
to Ruby on Rails: Talk


Issue got fixed after I recreate the project after upgrading rails.

Liz
Reply all
Reply to author
Forward
0 new messages