Prev | Current Page 270 | Next

David Berube

"Practical Reporting with Ruby and Rails"

rb)
class HomeController < ApplicationController
end
Save this as app/controllers/home_controller.rb.
Next, create a controller for uploading Apache log files, as shown in Listing 10-2.
Listing 10-2. Log Controller (app/controllers/logs_controller.rb)
require 'benchmark'
require 'tempfile'
require 'ar-extensions'
# Note that some developers would prefer to put the above
# require statements in the config/environment.rb file.
CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 193
class LogsController < ApplicationController
def upload
flash[:notice] = "Uploaded new file... \n"
count=0
if params[:upload_with_active_record_extensions]
# If the user chose the Active Record extensions
# button, we'll use that and measure the time
# it took.
real_time_elapsed = Benchmark.realtime do
columns = [:user_agent, :path_info, :remote_addr,
:http_referrer, :status, :visited_at]
values = []
LogParser.new.parse_io_stream(params[:log][:file]) do |l|
values <<
[ l['HTTP_USER_AGENT'],
l['PATH_INFO'],
l['REMOTE_ADDR'],
l['HTTP_REFERER'],
l['STATUS'],
Date.


Pages:
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
mapa komunikator A*Teens grafika biaƂystok Futro pomoce dydaktyczne