Prev | Current Page 289 | Next

David Berube

"Practical Reporting with Ruby and Rails"

If you set this variable
to false, or don??™t set it at all, the PDF will be downloaded instead.
After that, the code loops through the graph temporary files and deletes them. (You
cannot use Ruby??™s built-in Tempfile class here because you cannot specify a file extension,
and both Gruff and rpdf use the file extension to determine the file format.)
The .rpdf view (Listing 10-7) is in app/views/report/combined.pdf.rpdf. As you can
see, the code is reasonably straightforward:
pdf.select_font "Times-Roman"
figure_number = 1
@graph_files.each do |title, graph|
pdf.image graph
pdf.text "Figure #{figure_number
} of #{@graph_files.length
}- #{title}
", :left=>6, :font_size=>12
figure_number = figure_number + 1
end
This code loops through the graphs passed by the controller and uses the image
method from the PDF::Writer library to insert the image. Next, it labels each one with a
figure number and a title.
Next, let??™s examine the three protected functions in the report controller, app/
controllers/report_controller.


Pages:
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
teksty piosenek Ricky Martin Pat Metheny MonsterGod MBrother