rb.
Now, define a controller that creates your reports, as shown in Listing 10-3.
Listing 10-3. Report Controller (app/controllers/report_controller.rb)
require 'tempfile'
require 'gruff'
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
}
# Note that the key is the label and the value is the
CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 195
# 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
protected # Protected functions are for internal use only and
# don't correspond to a URL.
# This function is used by the two graph functions to create a
# temporary filename.
def get_tempfile_name(prefix)
File.
Pages:
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284