0

Ruby 2.3.0 & Rails 4.2.4

I am currently trying to download some files using the Rails send_file method and receive a 'no_method' error. I am using ActiveAdmin to access .csv files stored in AWS and trying to create a batch_action that will download each file that I have selected by accessing a batch_download method. Why can't I seem to use the send_file method?

class File_Upload
  def batch_download
    send_file "file_name"
  end
end

...

ActiveAdmin.register File_Upload do
  batch_action :download, confirm "Are you sure?" do |id|
    File_Upload.find(id).each {|file| file.batch_download}
  end
end
MZaragoza
  • 10,108
  • 9
  • 71
  • 116
Tim Park
  • 2,446
  • 2
  • 11
  • 13
  • is the problem that the file is being open into a browser and not downloading? – MZaragoza Mar 04 '16 at 22:50
  • @MZaragoza No, I get a 'no_method' error when using send_file. But I have now looked into another option using 'net/http', which does in fact download the files. The problem is now that the files are being downloaded into my app's parent directory and I want them to download into my '~/Downloads' directory. content = Net::HTTP.get(URI("#{self.file.to_s}")) File.open("#{self.file.to_s.split(/\d\//).last}", "w+") do |file| file.write(content) end` – Tim Park Mar 04 '16 at 23:02
  • Okay, so it turns out that send_file is a controller action, and I was trying to call it in a model. So there's the first mistake. It also appears that HTTP doesn't support more than one file download at a time. [Source](http://stackoverflow.com/questions/2339440/download-multiple-files-with-a-single-action) – Tim Park Mar 04 '16 at 23:30

0 Answers0