wicked_pdf,无法呈现 pdf
wicked_pdf, Unable to render pdf
我正在尝试使用 wicked_pdf 生成 pdf,但出现错误 'Unable to render template'。我已按照 wicked_pdf 指南进行操作,但我被卡住了。任何帮助表示赞赏。
url:
http://localhost:3000/app/letters/1.pdf
app/controllers/app/letters_controller.rb:
def show
respond_to do |format|
format.html
format.pdf do
render pdf: "Letters" # Excluding ".pdf" extension.
end
end
end
显示页面 link:
<li><a href="<%= app_letter_path(@letter, format: :pdf) %>" target="_blank"> Print</a></li>
app/views/app/letters/show.pdf:
<!doctype html>
<html>
<head>
</head>
<body>
<div>
<p>test</p>
</div>
</body>
</html>
宝石文件:
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
错误:
无法加载 PDF 文档。
Wicked PDF 在此处查看可用选项
- 在
views/layouts/pdf.html.erb
中为 pdf 文档创建布局
<!DOCTYPE html>
<html>
<head>
<title>My PDF</title>
<%#= wicked_pdf_stylesheet_link_tag "style" -%>
</head>
<body>
<div class='my_container'>
<%= yield %>
</div>
</body>
</html>
2- 在控制器中(您必须将选项添加为 disposition: 'inline'
才能在新选项卡中打开)
def show
respond_to do |format|
format.pdf do
render pdf: "show",
disposition: 'inline',
stream: false,
layout: 'layouts/pdf.html.erb'
end
end
end
3 - Pdf html 文档名称应以 .erb
结尾,即 app/views/app/letters/show.pdf.erb
<div>
<p>test</p>
</div>
我正在尝试使用 wicked_pdf 生成 pdf,但出现错误 'Unable to render template'。我已按照 wicked_pdf 指南进行操作,但我被卡住了。任何帮助表示赞赏。
url:
http://localhost:3000/app/letters/1.pdf
app/controllers/app/letters_controller.rb:
def show
respond_to do |format|
format.html
format.pdf do
render pdf: "Letters" # Excluding ".pdf" extension.
end
end
end
显示页面 link:
<li><a href="<%= app_letter_path(@letter, format: :pdf) %>" target="_blank"> Print</a></li>
app/views/app/letters/show.pdf:
<!doctype html>
<html>
<head>
</head>
<body>
<div>
<p>test</p>
</div>
</body>
</html>
宝石文件:
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
错误:
无法加载 PDF 文档。
Wicked PDF 在此处查看可用选项
- 在
views/layouts/pdf.html.erb
中为 pdf 文档创建布局
<!DOCTYPE html> <html> <head> <title>My PDF</title> <%#= wicked_pdf_stylesheet_link_tag "style" -%> </head> <body> <div class='my_container'> <%= yield %> </div> </body> </html>
2- 在控制器中(您必须将选项添加为 disposition: 'inline'
才能在新选项卡中打开)
def show
respond_to do |format|
format.pdf do
render pdf: "show",
disposition: 'inline',
stream: false,
layout: 'layouts/pdf.html.erb'
end
end
end
3 - Pdf html 文档名称应以 .erb
结尾,即 app/views/app/letters/show.pdf.erb
<div>
<p>test</p>
</div>