【发布时间】:2012-01-04 06:31:08
【问题描述】:
我正在使用 prawn gem 生成 PDF 报告,
@user.description returns as string "<b>sample text</b> &nspb; <p>sample text</p>"
同时将值附加到 pdf 表中
pdftable = Prawn::Document.new
pdftable.table([["#{@user.description}"]],
:column_widths => {0 => 50, 1 => 60, 2 => 280, }, :row_colors => ["ffffff"])
在这种情况下生成的 pdf 包含带有 html 标签的内容,即使我尝试应用 html_safe 但它没有转义标签。
是否可以在 prawn pdftable 中使用/应用 html_safe,以转义 html 标签?
【问题讨论】:
-
PDF 中究竟显示了什么,您想要显示什么?
-
在 pdf 中显示 "sample text &nspb;
sample text
" ,而应该只是文本,即“Sample text sample text”,应该应用 html_safe -
抱歉,
html_safe不是这样做的——它只是告诉 Rails 在视图中使用时不应转义字符串。查看this question 以获得解决方案。 -
如何使 htMl_safe 在控制器中工作,或者是否有任何替代方法。
-
您是否尝试过都一样,但没有引号?
pdftable.table([[@user.description.html_safe]] ...
标签: ruby-on-rails