pdfkit发送数据

发布于 2024-11-19 06:42:07 字数 602 浏览 7 评论 0原文

我正在尝试将 pdf 发送给用户。例如,如果用户位于 /products?category_id=3 中,他必须获取类别 id 为 3 的产品的报告,而不是所有报告。我找不到传递参数的方法。我该怎么做?

products_controller

def index
   @products Product.where("category_id = ?", params[:category_id)
end  

def reporter 
   kit = PDFKit.new(render_to_string(:action => "products/index", :layout => "report"))
   send_data(kit.to_pdf, :type => :pdf) 
end

我的看法是这样的

<% @products.each do |product| %>
<%= product.name %>
<% end %>

<%= link_to "Download(PDF)", reporter_path, :method => :post %>

I'm trying to send pdf to user. For example if user is in /products?category_id=3 he has to get report of products whose category id is 3 not all reports. I couldn't find a way to pass parameter. How can i do this ?

products_controller

def index
   @products Product.where("category_id = ?", params[:category_id)
end  

def reporter 
   kit = PDFKit.new(render_to_string(:action => "products/index", :layout => "report"))
   send_data(kit.to_pdf, :type => :pdf) 
end

My view is like this

<% @products.each do |product| %>
<%= product.name %>
<% end %>

<%= link_to "Download(PDF)", reporter_path, :method => :post %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文