Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template format undefined - suggested fix #2

Closed
beerlington opened this issue Dec 19, 2009 · 2 comments
Closed

Template format undefined - suggested fix #2

beerlington opened this issue Dec 19, 2009 · 2 comments

Comments

@beerlington
Copy link

I had some issues rendering my *.html.erb templates. If I didn't specify the path as an option, it didn't know to to use the html format and would try to load .erb, without the "html. If I did specify the path, but the template loaded a partial called _.html.erb, it would have the same problem. The only solution I can find that works is to specify the template with:

@template.template_format = :html

Since all my templates are html, I have just put this in the make_pdf function within pdf_helper.rb. It could easily be setup as an option if you don't want HTML as the default template format when rendering a PDF.

@kritik
Copy link

kritik commented May 30, 2010

I couldn't folow your advice but I did next (not very good solution)
def show
@Invoice = Invoice.find(params[:id])
get_extras

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @invoice }
  format.pdf  { redirect_to :action => :show_pdf, :template_format => :html}
end

end

def show_pdf
@Invoice = Invoice.find(params[:id])
get_extras
respond_to do |format|
format.html do
render :pdf => "invoice_"+params[:id],
:template => "invoices/show"
end
end
end

@bradcrawford
Copy link

This is how I solved the issue.

def make_pdf(options = {})
  options[ :format ] ||= :pdf
  html_string = render_to_string_with_format( :template => options[:template], :layout => options[:layout], :format => options[:format] )
  w = WickedPdf.new(options[:wkhtmltopdf])
  w.pdf_from_string(html_string, options)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants