Rails4:PDFKit缺少模板错误(Rails4: Template is missing error with PDFKit)
我想生成PDF文件,所以我试图使用PDFKit但失败了。
单击链接时显示以下错误。
ActionView::MissingTemplate (Missing template /show with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/usr/local/rvm/gems/ruby-2.3.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates" * "/home/ubuntu/workspace/app/views" * "/usr/local/rvm/gems/ruby-2.3.0/gems/web-console-2.0.0.beta3/app/views"
时间表\ show.html.erb
<% provide(:title, @schedule.title) %> <%= render @schedules %>
schedules \ _schedule.html.erb
... <%= link_to "PDF", schedule_path(schedule.id, format: "pdf"), class: "btn btn-sm btn-default" %> ...
schedules_controller.rb
... respond_to do |format| format.html # show.html.erb format.pdf do html = render_to_string template: "show" pdf = PDFKit.new(html, encoding: "UTF-8") send_data pdf.to_pdf, filename: "#{@scheudles.id}.pdf", type: "application/pdf", disposition: "inline" end end ...
虽然我创建了
show.pdf.erb
和_schedule.pdf.erb
,其内容与_schedule.pdf.erb
相同,但结果是一样的。I'd like to generate PDF file, so I am trying to use PDFKit but failing.
The following error was displayed when I click the link.
ActionView::MissingTemplate (Missing template /show with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/usr/local/rvm/gems/ruby-2.3.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates" * "/home/ubuntu/workspace/app/views" * "/usr/local/rvm/gems/ruby-2.3.0/gems/web-console-2.0.0.beta3/app/views"
schedules\show.html.erb
<% provide(:title, @schedule.title) %> <%= render @schedules %>
schedules\ _schedule.html.erb
... <%= link_to "PDF", schedule_path(schedule.id, format: "pdf"), class: "btn btn-sm btn-default" %> ...
schedules_controller.rb
... respond_to do |format| format.html # show.html.erb format.pdf do html = render_to_string template: "show" pdf = PDFKit.new(html, encoding: "UTF-8") send_data pdf.to_pdf, filename: "#{@scheudles.id}.pdf", type: "application/pdf", disposition: "inline" end end ...
Although I create
show.pdf.erb
and_schedule.pdf.erb
which contents is the same ashtml.erb
, the result is the same.
原文:https://stackoverflow.com/questions/39431808
满意答案
您应该创建一个由
servername
和datetime
键入的字典示例:from collections import defaultdict
lines = defaultdict(dict) with open("file_parse.txt") as f: for line in f: parts = line.split() key = tuple(parts[1:3]) # unique key with servername and datetime lines[key][parts[0]] = parts[3] lines[key]["servername"] = parts[1] lines[key]["datetime"] = parts[3] res = list(lines.values()) print(res) # [ # {'cpudile': 'NaN', 'cpunice': '0.0', 'cpunumber': '40.0', 'cpusystem': '0.0', 'cpuuser': '0.0', 'cpuwait': '0.0', 'datetime': 'NaN', 'servername': '1438084445'}, # {'cpudile': 'NaN', 'cpunice': '0.0', 'cpunumber': '40.0', 'cpusystem': '0.0', 'cpuuser': '0.0', 'cpuwait': '0.0', 'datetime': 'NaN', 'servername': '1438084440'}, # {'cpudile': 'NaN', 'cpunice': '0.0', 'cpunumber': '40.0', 'cpusystem': '0.0', 'cpuuser': '0.0', 'cpuwait': '0.0', 'datetime': 'NaN', 'servername': '1438084450'} # ]
You should create a dictionary that is keyed by
servername
anddatetime
Example: from collections import defaultdict
lines = defaultdict(dict) with open("file_parse.txt") as f: for line in f: parts = line.split() key = tuple(parts[1:3]) # unique key with servername and datetime lines[key][parts[0]] = parts[3] lines[key]["servername"] = parts[1] lines[key]["datetime"] = parts[3] res = list(lines.values()) print(res) # [ # {'cpudile': 'NaN', 'cpunice': '0.0', 'cpunumber': '40.0', 'cpusystem': '0.0', 'cpuuser': '0.0', 'cpuwait': '0.0', 'datetime': 'NaN', 'servername': '1438084445'}, # {'cpudile': 'NaN', 'cpunice': '0.0', 'cpunumber': '40.0', 'cpusystem': '0.0', 'cpuuser': '0.0', 'cpuwait': '0.0', 'datetime': 'NaN', 'servername': '1438084440'}, # {'cpudile': 'NaN', 'cpunice': '0.0', 'cpunumber': '40.0', 'cpusystem': '0.0', 'cpuuser': '0.0', 'cpuwait': '0.0', 'datetime': 'NaN', 'servername': '1438084450'} # ]
相关问答
更多有什么数据库专业书籍介绍?
在python写入新数据后,Logstash无法(读取和)存储文件中的日志数据(Logstash can't (read and) store log data from a file after python write new data into it)
将MySQL表转储为CSV文件,并使用Python脚本将其保存到指定的位置(Dump a MySQL table to a CSV file and save it in a given location using Python script)
试图在我的一个Python脚本文件中存储原始字节(Trying to store raw bytes inside my one Python script file)
Python脚本从文件中读取数据并将其存储在mysql表中(Python script to read data from a file and store it in mysql table)
如何从SQL数据库中读取数据并将其存储到XML文件中?(How to read data from SQL database and store it into an XML file?)
无法将mysql中的特殊字符存储到json文件中 - Python(unable to store special characters from mysql into a json file - Python)
如何从XML文件中读取数据并将其存储到数据库(MySQL)中?(How to read data from an XML file and store it into database (MySQL)?)
python:从文件读取行并将其存储在列表中(python: read line from file and store in list)
相关文章
更多Solr Document [null] missing required field: id 的原因
Rails4 已经移出了params可以解析xml的功能,拿rails4做微信API的童鞋们注意了
eclipse里报:An internal error occurred during:
[Hadoop] Error: JAVA_HOME is not set
《数据结构与STL》(Data Structures and the Standard Template Library)扫描版[PDF]
《Joomla 2.5 模板教程:宁皓网》(Create a Joomla 2.5 Template)前两章 + 模板资源[光盘镜像]
The connection to adb is down, and a severe error has occured.
solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias
Rails 风格指导
Solr安装异常:SolrException: Error loading class 'solr.VelocityResponseWriter'
最新问答
更多python的访问器方法有哪些
使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
透明度错误IE11(Transparency bug IE11)
linux的基本操作命令。。。
响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(box-shadow behaviour on elements)
它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640
Copyright ©2023
peixunduo.com All
Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!