I am having difficulty with the rails render_to_string function. I have created an app using the --api flag, so i think this may be the issue as i have tested in 'full' rails apps and its works just fine.
Essentially i am calling:
body_html = render_to_string(template: 'reservations/print')
I have also tried
body_html = render_to_string('reservations/print')
body_html = render_to_string(partial: 'reservations/print')
body_html = render_to_string(partial: 'reservations/print.html.erb')
which should return the html for that template. The filename is print.html.erb and just has basic data i.e.
<p> Hello world. </p>
When i output the body_html it is empty.
I referenced this SO question What is the correct way to render_to_string in wicked pdf? and am also going to use Wicked PDF to generate a pdf file.
Many thanks
reservations/print
without the template keyword? – Coulombe--api
flag is the problem. According to the documentaiton on Rails Api,AbstractController::Rendering
comes in default and this Module contains therender_to_string
method. – Coulombe