Wicked_PDF 仅下载 - Rails 3.1
我目前运行 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'%>
我的控制器。
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,但完全不知道如何在这种情况下使用它。
任何帮助表示赞赏。
I currently run Rails 3.1 and am using the latest version of Wicked_pdf for PDF generation.
I have set everything up correctly, and PDFs are generated just fine.
However, I want the user to be able to click a button to DOWNLOAD the pdf. At the present time, when clicked, the browser renders the pdf and displays it on the page.
<%= link_to "Download PDF", { :action => "show", :format => :pdf }, class: 'button nice red large radius', target: '_blank'%>
My 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
I have been pointed towards send_file, but have absolutely no idea how to use it in this scenario.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
分解您需要设置为“附件”的配置,例如:
Decomposition the config you need to set as 'attachment', example:
我就是这样做的:
它对我有用;-)
I am doing it that way:
and it works for me ;-)
让我们尝试一下:
Let's try: