I can export a CSV when I make a request from my localhost to my project folder, but I can't figure out how to export it to my browser downloads folder from the localhost. I am using the send_data method as shown below. Any ideas?
class FitbitApiController < ApplicationController
before_filter :authenticate_user!
def data_request
client = current_user.fitbit_client
output_filename = ''
case params[:resource]
when 'daily_activity_summary'; output = client.activity_time_series(resource: 'calories', start_date: params[:date], period: '1d')
output_filename = 'daily_activity_summary.csv'
when 'sleep'; output = client.sleep_logs(params[:date])
output_filename = 'sleep.csv'
when 'activities/steps'; output = client.activity_time_series(resource: 'steps', start_date: params[:date], period: '1d')
output_filename = 'steps.csv'
when 'weight'; output = client.weight_logs(start_date: params[:date])
output_filename = 'weight.csv'
end
# Determine filename based on value of params[:resource]
filename = params[:resource].split('/').last
# Write data to CSV
require 'json_converter'
converter = JsonConverter.new
converter.write_to_csv(output, output_filename, headers = true, nil_substitute = '')
send_data output_filename, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment;output=#{output}.csv"
end
end