print index table with 大虾 ruby on rails
Print index table with prawn ruby on rails
我在尝试在我的应用程序索引中打印搜索生成的数组时遇到问题。这是我的代码:
约会控制器(索引操作):
def index
@appointments = Appointment.search(params[:search])
respond_to do |format|
format.html
format.pdf do
pdf = AppointmentsPdf.new(@appointments)
send_data pdf.render, filename: "citas_del_dia",
type: "application/pdf",
disposition: "inline"
end
end
end
索引视图:
<%= form_tag @appointments_path, :method => 'get', :id => "appointments_search" do %>
<%= date_field_tag :search, params[:search] %>
<%= submit_tag "search date", :name => nil %>
<% end %>
<div><%= render 'appointments' %></div>
<%= link_to "Print appointments of the day",appointments_path(@appointments, :format => 'pdf'), target: "_blank" %>
还有我的大虾pdfclass:
class AppointmentsPdf < Prawn::Document
def initialize(appointments)
super(top_margin: 30, :page_layout => :landscape)
@appointments = appointments
#some code to fill the pdf.
现在的问题是,当我搜索特定日期时,它可以很好地呈现索引,但是当我想将该页面打印为 pdf 时,它什么也不打印,就好像搜索为 null 而不是 null 一样。我想我必须将搜索像参数一样传递给大虾 class 但我不知道在哪里或如何。
我通过 link 将搜索参数传递给这样的方法来解决它:
<%= link_to "appointments of the day", citas_del_dia_appointments_path(@appointments, :format => 'pdf', :search => params[:search]), target: "_blank" %>
现在它就像一个魅力
我在尝试在我的应用程序索引中打印搜索生成的数组时遇到问题。这是我的代码:
约会控制器(索引操作):
def index
@appointments = Appointment.search(params[:search])
respond_to do |format|
format.html
format.pdf do
pdf = AppointmentsPdf.new(@appointments)
send_data pdf.render, filename: "citas_del_dia",
type: "application/pdf",
disposition: "inline"
end
end
end
索引视图:
<%= form_tag @appointments_path, :method => 'get', :id => "appointments_search" do %>
<%= date_field_tag :search, params[:search] %>
<%= submit_tag "search date", :name => nil %>
<% end %>
<div><%= render 'appointments' %></div>
<%= link_to "Print appointments of the day",appointments_path(@appointments, :format => 'pdf'), target: "_blank" %>
还有我的大虾pdfclass:
class AppointmentsPdf < Prawn::Document
def initialize(appointments)
super(top_margin: 30, :page_layout => :landscape)
@appointments = appointments
#some code to fill the pdf.
现在的问题是,当我搜索特定日期时,它可以很好地呈现索引,但是当我想将该页面打印为 pdf 时,它什么也不打印,就好像搜索为 null 而不是 null 一样。我想我必须将搜索像参数一样传递给大虾 class 但我不知道在哪里或如何。
我通过 link 将搜索参数传递给这样的方法来解决它:
<%= link_to "appointments of the day", citas_del_dia_appointments_path(@appointments, :format => 'pdf', :search => params[:search]), target: "_blank" %>
现在它就像一个魅力