martincarlin87
martincarlin87

Reputation: 11052

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.

Upvotes: 1

Views: 1096

Answers (2)

martincarlin87
martincarlin87

Reputation: 11052

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.

Upvotes: 1

Ismael
Ismael

Reputation: 16730

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.

Upvotes: 0

Related Questions