After downloading showing empty file

def export_rawdata
@device = Device.find_by_id( params[:id] )
@messages = @device.devmessages.all( :order => “id”, :conditions =>
[“packettime >= ? and packettime <= ?”, params[:start_time],
params[:end_time]] )
raw_data_path = “#{Rails.root}/tmp/exports/#{@device.s_dev_name}.csv”
File.open(raw_data_path, “w+”) do |csv|
csv.write [“Packet”,“Created At”]

@messages.each_with_index do |m,i|
  x = m.created_at
   csv.write [m.message, x.strftime('%h %d, %G %r')]
 end

end
send_file raw_data_path, :type => “application/zip”, :x_sendfile =>
true

end

Able to store the data file in a tmp/exports But when i click on
download , it is downloading the empty file.

What is the mistake i have done in my code?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs