gpt4 book ai didi

ruby-on-rails - Wicked_PDF 仅下载 - Rails 3.1

转载 作者:行者123 更新时间:2023-12-03 18:18:14 25 4
gpt4 key购买 nike

我目前运行 Rails 3.1 并使用最新版本的 Wicked_pdf 生成 PDF。
我已经正确设置了所有内容,并且生成的 PDF 文件也很好。

但是,我希望用户能够单击按钮来下载 pdf。目前,当单击时,浏览器会呈现 pdf 并将其显示在页面上。

<%= link_to "Download PDF", { :action => "show", :format => :pdf }, class: 'button nice red large radius', target: '_blank'%>

我的 Controller 。
def show
@curric = Curric.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @curric }
format.pdf do
render :pdf => @curric.name + " CV",
:margin => {:top => 20,
:bottom => 20 }

end
end
end

我一直在使用 send_file,但完全不知道如何在这种情况下使用它。

任何帮助表示赞赏。

最佳答案

分解你需要设置为'附件'的配置,例如:

respond_to do |format|
format.pdf do
render pdf: @curric.name + " CV",
disposition: 'attachment'
end
end

关于ruby-on-rails - Wicked_PDF 仅下载 - Rails 3.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7915078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com