CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 205
Dissecting the Code
Users can take three actions in this application:
??? Upload a log, which adds the data from that log to the application.
??? Clear all of the data from the system, which can be useful if incorrect data was
entered.
??? View a report.
Let??™s examine the log uploader code (Listing 10-2), which is in app/controllers/
logs_controller.rb. The first thing that the script does is require a few libraries:
require 'benchmark'
require 'tempfile'
require 'ar-extensions'
Some developers would prefer to put these require statements in their config/
environment.rb file instead of at the top of the controller; I prefer this method, but it??™s not
an extremely important distinction.
Next, this controller has just a single method, which controls the uploading. It has
two different methods of uploading, and they are triggered by two different buttons. The
first uploads with Active Record alone, which looks like this:
# If the user chose the "Upload with Active Record" button,
# then use regular Active Record to upload the records and
# measure the time it takes.
Pages:
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296