I have a form that takes date range value to generate a report with Jasper Reports
reports/statistic.html.erb
<%= form_tag("/reports/statistic", :method => "post", :target => "_blank") do %>
<%= label_tag(:from_date, "From Date:") %>
<%= text_field_tag :from_date %>
<%= label_tag(:to_date, "To Date:") %>
<%= text_field_tag :to_date %>
<br><br>
<%= submit_tag("Generate Report") %>
<% end %>
and this is reports_controller.rb
def statistic
@details=StatisticTable.where(:dateindb => (params[:from_date])..(params[:to_date])
send_doc(render_to_string(
:template => 'reports/statistic.xml', :layout => false), #source of xml and template
'/statistic/detail', #xml xpath2 query in reports
'statisticreport', #name of .jasper file
'StatisticReport', #name of pdf file
'pdf')
end
When I clicked Generate Report button, the report displays nicely in a pdf viewer in a new window. But when I try to save the pdf file, the pdf is empty and the date value is returned as null.
Also, I followed this tutorial http://oldwiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports which explains where the send_doc method comes from.
I don’t think the problem is in Jasper because if I replace this
@details=StatisticTable.where(:dateindb => (params[:from_date])..(params[:to_date])
with a pre-defined date value
@details=StatisticTable.where(:dateindb => ('2011-12-01')..('2011-12-31')
the report displays and saves perfectly. So I’m guessing there is something wrong with my Ruby on Rails variables setting?
Thanks!
I solved this by only changing form method to GET
and after report is generated in PDF, I clicked Save and the PDF saves the whole data perfectly.