I am using rails 5
and grape gem
for building my application. Now I have a requirement of generating a PDF and send back to the response using grape
endpoint. I am using wicked_pdf
gem and wkhtmltopdf-binary
for generate PDF. But I am facing the issue of undefined method 'render_to_string'
.
I have tried various way to resolve it. but couldn't find any solution.
Below is my code snippet
API Endpoint:
module Endpoints
class GeneratePdf < Grape::API
get do
users = User.all # I want this users list in my PDF
pdf = WickedPdf.new.pdf_from_string(render_to_string('users/index.html.erb')) # placed in app/views/users/pdf.html.erb
# some code here for send pdf back to response
end
end
end
Gemfile:
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
Config > initializers > mime_types.rb
Mime::Type.register "application/pdf", :pdf