我正在使用带有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发送到第三方传真服务.
谢谢你的帮助.
瑞安
stylesheet_link_tag控制器是否有呼叫?我正在内存中创建一个 PDF 文件,并将其传递给另一个服务的 api 调用。我正在使用 PDFKit,它要求我向其发送样式表链接。我使用的是 Rails 3.1,因此需要通过此方法访问资产管道。
谢谢您的帮助!
我有一个对象数组,例如:
[#<Something id: 34175, name: "abc", value: 123.3, comment: "something here">,
#<Something id: 34176, name: "xyz", value: 123.3, comment: "something here">,
#<Something id: 34177, name: "xyz", value: 227.3, comment: "something here sdfg">,
#<Something id: 34178, name: "xyz", value: 123.3, comment: "something here sdfg">]
Run Code Online (Sandbox Code Playgroud)
我想返回所有不具有相同名称和值的元素.所以在这种情况下,返回将是:
[#<Something id: 34175, name: "abc", value: 123.3, comment: "something here">,
#<Something id: 34176, name: "xyz", value: 123.3, comment: "something here">,
#<Something id: 34177, name: "xyz", value: 227.3, comment: "something here sdfg">]
Run Code Online (Sandbox Code Playgroud)
我所关心的只是名称和价值.
我尝试将一个块传递给uniq方法,但我无法弄清楚如何匹配两个元素而不仅仅是一个元素.