开发者

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

开发者 https://www.devze.com 2023-01-18 08:44 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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