Search code examples
ruby-on-railsrubyruby-on-rails-2pdfkit

Rails 2 How to Render a view as a string


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.


Solution

  • 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.