4

In rails 4, I am using grape gem for mobile app features. In mobile app, I need to provide download .pdf file option. I have referred this How to allow Binary File download using GRAPE API but file is not generating here.

Other than mobile app(in web side) I have downloading a file using,

file_path = "#{Rails.root}/public/downloads/#{@user.id}_guide.pdf"
pdf = WickedPdf.new.pdf_from_string(render_to_string('public/guide/template', :layout=> false))
File.open(file_path, 'wb') do |file|
  file << pdf
end
return file_path

Please help me to write an API which generates and downloads a .pdf file

Community
  • 1
  • 1
Shruthi R
  • 1,863
  • 4
  • 39
  • 77
  • You are just returning a String that represents the path to the file. You need to actually read out that file eg. `File.open(file_path,&:read)` as well as set the appropriate headers for the MIME type and disposition. Read the post you are referencing and it will solve this for you.. – engineersmnky Aug 17 '16 at 13:14
  • As per the reference, file is not generating. How to generate .pdf file? – Shruthi R Aug 18 '16 at 06:45

0 Answers0