Reputation: 6639
Rails 5.1
In app/controllers/fw_exports_controller.rb, I have:
def download_csv
followed = Followed.find(params[:followed_id])
file_path = "#{Rails.root.to_s}/csv_container/#{followed.screen_name}_locations.csv"
send_file (file_path), :type => "text/csv", :disposition => 'inline'
redirect_to root_path, notice: t('fw_exports.spreadsheet_export.download_ok')
end
When this executes, I see the following in my log file:
Started POST "/download_csv" for 75.151.110.193 at 2017-12-12 22:31:56 +0000
Processing by FwExportsController#download_csv as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "followed_id"=>"followed.1510895564.0013862", "button"=>""}
Followed Load SELECT `followeds`.* FROM `followeds` WHERE `followeds`.`id` = 'followed.1510895564.0013862' LIMIT 1
Sent file /home/fwtest/rails/csv_container/wm_locations.csv (0.2ms)
Redirected to http://fwtest.myapp.com/
I verified that /home/fwtest/rails/csv_container/wm_locations.csv is there and it's a CSV, but nothing downloads to my local PC.
Any ideas what I'm doing wrong?
Upvotes: 0
Views: 30
Reputation: 2483
Remove redirect_to
. If you have both send_file
and redirect_to
you are sending two responses - file and redirect. You are redirecting to root_path
and the download does not start.
Upvotes: 1