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
更新时间:2024-04-21 20:04
最满意答案
您应该创建一个由
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'} # ]
相关问答
更多-
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
从我收集的内容来看,源文件是elk_data_source.log,并且您正尝试将"eventType" = ["*icbc"]覆盖为*ABC 。 但是你错过的是...... "eventType"值是一个数组 ,你用一个单一的值来写它 - *ABC 。 将data["eventType"] = "*ABC"更改为data["eventType"] = ["*ABC"] 。 这应该解决。 如果可能,尝试将这两个文件与文件比较软件进行比较。 此外,请检查从文件读取和格式化时可能导致问题的匹配大括号或其他空间。 ...
-
改变这个: with open('/full/path/tofile/Data on %s.csv' % currentDate ,'w') as f: 这解决了你的问题X.但是你有一个问题Y.那就是'我如何有效地从mysql转储CSV数据,而不必写很多代码?' 对问题Y的回答是SELECT INTO OUTFILE Change this: with open('/full/path/tofile/Data on %s.csv' % currentDate ,'w') as f: This solve ...
-
您应该对二进制文件进行编码 - 例如,使用base64封装 - 将字节转换为“合法字符”。 然后,当您需要二进制信息时,将其转换回来。 有关一些代码示例,请参阅此前一个问题 。 一个简短的示例,让您前进: # assume your bytes came from a file: bytesIneed = bytearray([234,232,231,188,122,132,145]) import base64 bytesConverted = base64.b64encode(bytesIneed) ...
-
Python脚本从文件中读取数据并将其存储在mysql表中(Python script to read data from a file and store it in mysql table)[2022-08-11]
您应该创建一个由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 ... -
如何从SQL数据库中读取数据并将其存储到XML文件中?(How to read data from SQL database and store it into an XML file?)[2023-07-29]
一种简单的方法(假设您使用的是SQL Server)是在检索数据的查询结尾附加FOR XML AUTO 。 然后这将返回结果集作为XML文件。 例如,以Northwind数据库为例,您可以使用此查询: SELECT * FROM Products as P INNER JOIN Categories as C ON P.CategoryID = C.CategoryID FOR XML AUTO 这将生成以下XML:无法将mysql中的特殊字符存储到json文件中 - Python(unable to store special characters from mysql into a json file - Python)[2023-04-28]
您似乎正在使用json编码的字符串创建ASCII编码的json文件,这是存储JSON文件的典型用例。 我想你想要一个UTF-8编码的json文件。 为此,请在json编码步骤中设置ensure_ascii=False ,以便将utf8编码的字符串直接传递给文件。 这样的事可能适合你。 import json master_objects = { "tomorrow" : "ma\xc3\xb1ana" # UTF-8 encoding, just like what comes from db } ...如何从XML文件中读取数据并将其存储到数据库(MySQL)中?(How to read data from an XML file and store it into database (MySQL)?)[2022-02-24]
您可以使用Castor witch是一个开源数据绑定框架,用于将数据从XML移动到Java编程语言对象以及从Java移动到数据库。 我在IBM developerWorks中找到了一篇文章系列,描述了使用适合您需求的Castor。 You could use Castor witch is an open source data binding framework for moving data from XML to Java programming language objects and from J ...首先,您可能打算在列表中调用append ,如list_1.append(a[0])和list_2的相应更改。 此外,如果稍后将a[0]视为数字,则可能需要追加float(a[0]) 。 IndexError可能来自输入中的空行(可能是最后一行)。 要解决它,可以在访问其元素之前检查len(a) ,或者确保代码只有干净的输入。 First, you probably meant to call append on the lists, as in list_1.append(a[0]) and the co ...相关文章
更多- 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'
最新问答
更多- 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
- 高考完可以去做些什么?注意什么?
- Allauth不会保存其他字段(Allauth will not save additional fields)
- Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
- sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
- 怎么在《我的世界》游戏里面编程
- .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
- 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
- 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
- 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
- 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
- 如何使用变量值创建参数类(How to create a parameter class with variant value)
- 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
- 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
- rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
- 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
- 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
- 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
- CSS修复容器和溢出元素(CSS Fix container and overflow elements)
- 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
- 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
- SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
- 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
- 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
- Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
- 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
- 函数调用可以重新排序(Can function calls be reordered)
- 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
- 如何解释SBT错误消息(How to interpret SBT error messages)
- 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)