简体   繁体   English

Rails 4中的response_to pdf

[英]respond_to pdf in Rails 4

I have an index controller action which responds to the pdf format which looks something like 我有一个响应于pdf格式的index控制器操作,看起来像

class ProposalsController < ApplicationController
  respond_to :pdf, :html
  def index
    @proposals = Proposal.all

    respond_with @proposals do |format|
      format.html
      format.pdf
    end
  end
end

Proposal has a to_pdf method which creates Prawn::Document . Proposal有一个to_pdf方法,该方法创建Prawn::Document How can I loop over each of the propsals, grab it's PDF, append it to a newly created PDF, and then render that in the browser via respond_with ? 如何遍历每个投标,获取其PDF文件,将其附加到新创建的PDF文件中,然后通过respond_with在浏览器中呈现它?

One can use rails API to create a personalized renderer. 可以使用rails API创建个性化渲染器。 In fact, the book Crafting Rails 4 Applications by José Valim show you how to create personalized PDF renderer in the first chapter. 实际上,JoséValim所著的Crafting Rails 4 Applications书在第一章中向您展示了如何创建个性化PDF渲染器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM