Marklar
Marklar

Reputation: 1267

Rails route to access files saved to tmp directory

In my background worker I'm creating a pdf and saving it to the tmp directory with:

save_path = Rails.root.join('tmp', unique_report_name)
File.open(save_path, 'wb') do |file|
  file << pdf
end

I then try to open the pdf in a new window and get ActionController::RoutingError (No route matches [GET] errors.

I've tried copying what they do with CarrierWave (I'm not using CarrierWave) by using the below in config.ru:

use Rack::Static, :urls => ['/tmp'], :root => 'tmp'

but I get the error File not found: /tmp/my_file_name.pdf even though the file does indeed exist in the location.

Upvotes: 3

Views: 4090

Answers (1)

Dmytro  Kharytonenko
Dmytro Kharytonenko

Reputation: 51

You should be able to reach that file using Rails.root

"#{Rails.root}/tmp/my_file_name.pdf"

Upvotes: 4

Related Questions