Search code examples
ruby-on-railsruport

Newbie - trying to save a datagrid to pdf


I'm using the gem datagrid to display some data. I would like to use ruport to output the data to pdf.

I added this button to my controller.rb=

<%= button_to "PDF", {:controller => :admin_reports, :action => :worequest_pdf }%>

I have this route=

resources :admin_reports do
post :worequest_pdf, :on => :collection

end

And this in the admin_reports_controller.rb=

 def worequest_pdf
f = File.new("worequest.pdf", "w")
f.write Ruport::Data::Table(:column_names =>report.header, :data => report.rows).to_pdf
f.close

end

But, it doesn't work - any ideas? I get:

undefined local variable or method `report' for #<AdminReportsController:0x007fc463566218> 

Solution

  • Ruport probably is not your best option. It has not been updated in more than a year. Thats a lifetime in the ruby world. You may want to look at http://ruby-statsample.rubyforge.org/reportbuilder/ or go to https://www.ruby-toolbox.com/ to find something more up to date.