Print index table with prawn ruby on rails -
i'm having trouble trying print array search produces in index of app. here code:
appointments controller (index action):
def index @appointments = appointment.search(params[:search]) respond_to |format| format.html format.pdf pdf = appointmentspdf.new(@appointments) send_data pdf.render, filename: "citas_del_dia", type: "application/pdf", disposition: "inline" end end end
index view:
<%= form_tag @appointments_path, :method => 'get', :id => "appointments_search" %> <%= date_field_tag :search, params[:search] %> <%= submit_tag "search date", :name => nil %> <% end %> <div><%= render 'appointments' %></div> <%= link_to "print appointments of day",appointments_path(@appointments, :format => 'pdf'), target: "_blank" %>
and prawn pdf class:
class appointmentspdf < prawn::document def initialize(appointments) super(top_margin: 30, :page_layout => :landscape) @appointments = appointments #some code fill pdf.
now problem renders index fine when search specific date when want print page pdf prints nothing if search null not. think have pass search parameter prawn class don't know or how.
i solved passing search param through link method so:
<%= link_to "appointments of day", citas_del_dia_appointments_path(@appointments, :format => 'pdf', :search => params[:search]), target: "_blank" %>
now works charm
Comments
Post a Comment