Prev | Current Page 288 | Next

David Berube

"Practical Reporting with Ruby and Rails"


Next, let??™s take a look at the code that generates the reports. First, the report controller
in app/controllers/report_controller.rb (Listing 10-3) uses rpdf to generate the
PDF view.
class ReportController < ApplicationController
def combined
@rails_pdf_inline = true
@graph_files = {
'Graph of per-sale costs'=>
get_sale_graph_tempfile,
'Graph of total visitors from each advertiser'=>
get_visitor_graph_tempfile
}
CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 208
# Note that the key is the label and the value is the
# graph filename. Note you could easily add more graphs in
# here if you'd like.
render :layout=>nil
# At this point, the images have already been embedded in the PDF,
# so we can safely delete them.
@graph_files.each do |label, filename|
File.unlink filename
end
end
This code creates a hash with labels and graph file names. It uses the two graphcreation
functions??”get_sale_graph_tempfile and get_visitor_graph_tempfile??”and
passes them to the .rpdf view combined. rpdf uses the @rpf_pdf_inline variable to specify
that the PDF should be displayed in the browser and not downloaded.


Pages:
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
mieszkania sosnowiec nowoczesne meble matchbox sklep agencja reklamowa poznań parasole reklamowe