Rails 3.1:将当前数据从 will_paginate 输出到 PDF
只要有时间,我已经使用 Rails 工作了几个星期了。我正在尝试创建应用程序当前显示的数据的 PDF 输出。我正在使用 prawn,它工作正常并且 will_paginate。是否可以将屏幕上显示的当前数据(例如所选页面)发送到 pdf 输出?
index.html.erb
:
<% @truckdeliveries.each do |truckdelivery| %>
...
<% end %>
<%= will_paginate @truckdeliveries %>
<%= link_to "PDF", truckdeliveries_path(@truckdelivery ,format: "pdf") %>
truckdeliveries_controller.rb
:
class TruckdeliveriesController < ApplicationController
def index
@truckdeliveries = Truckdelivery.paginate page: params[:page], order: 'created_at desc',
per_page: 10
respond_to do |format|
format.html # index.html.erb
format.json { render json: @truckdeliveries }
format.pdf do
pdf = TruckdeliveryPdf.new(@truckdeliveries)
send_data pdf.render, filename: "truckdelivery_.pdf",
type: "application/pdf"
end
end
end
...
这工作正常,但它只显示第一页的数据,如果我切换到另一个页面,它不会改变。我尝试将 link_to 更改为@truckdeliveries,但这只会创建一个神秘的链接。
我尝试过谷歌,但我仍然无法使用正确的流行语。因此,任何建议将不胜感激!
I've been working with rails for a few weeks now, whenever I had time. I'm trying to create a PDF output of the currently shown data of my application. I'm using prawn, which is working fine and will_paginate. Is it possible to send the current data, which is shown on the screen (e.g. the selected page), to the pdf output?
index.html.erb
:
<% @truckdeliveries.each do |truckdelivery| %>
...
<% end %>
<%= will_paginate @truckdeliveries %>
<%= link_to "PDF", truckdeliveries_path(@truckdelivery ,format: "pdf") %>
truckdeliveries_controller.rb
:
class TruckdeliveriesController < ApplicationController
def index
@truckdeliveries = Truckdelivery.paginate page: params[:page], order: 'created_at desc',
per_page: 10
respond_to do |format|
format.html # index.html.erb
format.json { render json: @truckdeliveries }
format.pdf do
pdf = TruckdeliveryPdf.new(@truckdeliveries)
send_data pdf.render, filename: "truckdelivery_.pdf",
type: "application/pdf"
end
end
end
...
This is working fine, but it only shows the data for the first page and doesn't change if I switch to another page. I tried changing the link_to to @truckdeliveries but that only creates one cryptic link.
I tried google but I'm still having trouble using the right buzz words. So any suggestions would be very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,它只打印第一页的原因是因为您的 PDF 链接不包含页面参数。试试这个吧。
It seems to me the reason that it is only printing the first page is because your PDF link isn't including the page parameter. Try this instead.