Ruby on rails 更新后将数据保存在pdf上
我有管理订单的申请。用户可以创建订单,并在创建订单后使用订单中的数据生成pdf。此pdf需要通过电子邮件发送给用户。 此外,pdf需要保存在表中的管理面板上,以便管理员可以下载它 问题是如何在创建订单后保存此pdf,以便任何更新价格或其他数据都不会影响已创建的pdf。PDF需要保留订购时的所有数据 应用程序在RubyonRails上 谢谢。使用wicked pdf gemRuby on rails 更新后将数据保存在pdf上,ruby-on-rails,ruby,pdf,Ruby On Rails,Ruby,Pdf,我有管理订单的申请。用户可以创建订单,并在创建订单后使用订单中的数据生成pdf。此pdf需要通过电子邮件发送给用户。 此外,pdf需要保存在表中的管理面板上,以便管理员可以下载它 问题是如何在创建订单后保存此pdf,以便任何更新价格或其他数据都不会影响已创建的pdf。PDF需要保留订购时的所有数据 应用程序在RubyonRails上 谢谢。使用wicked pdf gem 1.You must install https://code.google.com/p/wkhtmltopdf/ 2.In
1.You must install https://code.google.com/p/wkhtmltopdf/
2.Install the gem with the command "gem install wkhtmltopdf-binary"
3.Create a folder to save your pdf files like "/public/user_pdfs"
4.Configure your controller
class UserController < ApplicationController
def pdf_files
@users= User.all
respond_to do |format|
format.html
format.pdf {
send_data render(
####### WICKED CODE ######
:pdf => "user_pdfs" },
:save_to_file => Rails.root.join('public/user_pdfs', "name_of_pdf_on_Db.pdf")
),
####### END WICKED CODE ######
:filename => "name_of_pdf_in_view.pdf"
}
end
end
end
5.In the view "pdf_files.html.erb"just create a link to download the file
<% @users.each do |user| %>
<%= user.name %>
<%= link_to "DOWNLOAD PDF",{:controller=>"user",:action=>"pdf_files",:id=>user.id } %>
<% end %>
6.Create the pdf file just the information that you want to show ...."pdf_files.erb"
<% @users.each do |user| %>
<%= user.name %>
<% end %>
1.您必须安装https://code.google.com/p/wkhtmltopdf/
2.使用命令“gem Install wkhtmltopfdbinary”安装gem
3.创建一个文件夹以保存您的pdf文件,如“/public/user\u pdfs”
4.配置控制器
类UserControlleruser\u pdfs},
:save_to_file=>Rails.root.join('public/user_pdfs',“在_Db.pdf上的_pdf的名称”)
),
#######结束邪恶的代码######
:filename=>“视图中的pdf文件的名称”
}
结束
结束
结束
5.在“pdf_files.html.erb”视图中,只需创建一个链接即可下载该文件
“用户”,:action=>“pdf_文件”,:id=>user.id}%>
6.仅创建要显示的信息的pdf文件…“pdf_files.erb”
有关更多信息,请转到我正在使用对虾生成PDF。但你能解释一下这是怎么可能的吗?好的,没问题。我需要帮助或想法。任何东西谢谢,只有两行,没什么,没什么不正常的…而且比虾更简单…对不起,如果我现在帮不上忙…需要休息…如果你想在7小时内回答这个消息。等你。好吧。。。我编辑了答案,但我用的是虾宝石。它在我开始使用之前就已经使用过了,除了“存储到文件夹”之外,一切都很好。对虾宝石是否有储存到文件夹的选项??