我在我的控制器中使用PDFkit来构建一系列PDF,将它们压缩,然后将它们发送给用户.
为了控制输出样式,我告诉PDFKit在内容生成期间使用哪些样式表.我需要传递CSS文件的文件引用.由于Rails现在正在编译和重命名我的样式表,我不确定如何在我的控制器中引用已编译的CSS资产.
这是我以前做的事情:
InvoicesController < ApplicationController
def download
kit = PDFKit.new(render_to_string(:show, :layout => false))
kit.stylesheets << "#{Sass::Plugin.options[:css_location]}/application.css"
kit.to_file("#{file_date_string}.pdf")
# snip
end
end
Run Code Online (Sandbox Code Playgroud)
Sass :: Plugin.options [:css_location]现在返回错误的位置,更不用说application.css不再是文件的有效名称.我要指出,我有作为一个清单给我SCSS文件的应用程序/资产/ application.css文件,它是在我的意见通过stylesheet_link_tag()方法工作正常.
基本上我正在寻找的是一个控制器,相当于asset_path(),以便做这样的事情:
kit = PDFKit.new(render_to_string(:show, :layout => false))
kit.stylesheets << asset_path('application.css')
kit.to_file("#{file_date_string}.pdf")
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我正在使用带有rails 3.1的PDFkit.在过去,我能够使用render_to_string函数并从该字符串创建pdf.然后我按如下方式添加样式表.我的问题是我不知道如何从资产管道中访问它们.(这就是我在rails 3.0中的表现)
html_string = render_to_string(:template => "/faxes/show.html.erb", :layout => 'trade_request')
kit = PDFKit.new(html_string, :page_size => 'Letter')
kit.stylesheets << "#{Rails.root.to_s}/public/stylesheets/trade_request.css"
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何通过资产管道直接从我的控制器访问我的css文件?
我知道我可以使用带有PDFkit的Rack Middleware将pdf呈现给浏览器,但在这种情况下,我需要将pdf发送到第三方传真服务.
谢谢你的帮助.
瑞安