13

Below on line no. 2, I am getting this error:

Errno::ENOENT in OrdersController#print

def generate_receipt(filename = nil, current_user = nil)
    filename ||= "public/receipts/#{id}.pdf"
    Prawn::Document.generate(filename, :page_layout => :portrait, :page_size => 'LETTER', :skip_page_creation => false, :top_margin => 50, :left_margin => 50)do |pdf|

      pdf_receipt_data(pdf, false, 'store_front', current_user)

      pdf.number_pages "<page> of <total>", :at => [0, 0]

    end
end

On my localhost this code is working but on testing env I am getting this error. I am using rails 4.2.
Please help me out.

nempoBu4
  • 6,521
  • 8
  • 35
  • 40
Chitra
  • 1,294
  • 2
  • 13
  • 28

1 Answers1

22

After putting a complete path, resolved my problem.

filename ||= "#{Rails.root}/public/receipts/#{id}.pdf"

Chitra
  • 1,294
  • 2
  • 13
  • 28
  • 4
    thanks for the solution. same thing happened for me on rails 4.2, ruby 2.2.0. but I don't know why we have to put the complete path. – allenwlee Apr 11 '15 at 04:38
  • Same for Rails 7. I thought /public was a default directory to look. `<%= url = "#{Rails.root}/public/filename.geojson" %>` – Greg Mar 12 '23 at 19:57