开发者

How do i download prawn pdf file while using form submit? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.
def index
    @forms = Form.all
    respond_to do |format|
      format.html
    end
  end
    def submit
        respond_to do |format|
        format.pdf {render  }

    end
  开发者_Python百科  end

submit.pdf.prawn file
pdf.text "successfully submitted"


It is possible for Prawn to generate and return the PDF without having to to save locally...

def submit
  send_data(generate_pdf, :filename => "output.pdf", :type => "application/pdf") 
end

private 
def generate_pdf
    Prawn::Document.new do
        text "Hello Stackoverflow"
    end.render 
end


Use prawn to generate a pdf that's saved somewhere in your /public folder, like:

Prawn::Document.generate("#{RAILS_ROOT}/public/pdfs/myfile.pdf")

Then just use your controller to redirect users to that location:

redirect_to '/pdfs/myfile.pdf'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜