This is how I solved it:
html = render_to_string(:template => "/quotes/order.rhtml", :layout => false, :locals => { :id => quote_id })
The template
value is the physical path of the template in the views
directory and not the url.
Вопрос
I am using PDFKit to generate a pdf from a view but I can't seem to find an easy way to store the output from a url as a text string.
I tried this:
html = render_to_string(:template => "/portal/quotes/order/" + quote_id, :layout => false)
with quote_id being 216
in this case but I get this error:
Missing template /portal/quotes/order/216.erb in view path app/views
All my views are .rhtml
format, not sure where it's getting the .erb
extension from.
The url works as expected when navigated to in the browser.
Решение
This is how I solved it:
html = render_to_string(:template => "/quotes/order.rhtml", :layout => false, :locals => { :id => quote_id })
The template
value is the physical path of the template in the views
directory and not the url.
Другие советы
You need to pass a template path on the template param, not a relative url. The template path you want to use should be something like 'orders/show'
or something like that. And this must be located at the views folder.