I started to write a small Rails Log Analyzer that provides some insight on how a given application is used. I’ve just spent three hours so far, so not too much to show, but I have found the integration of Flex with Rails for read-only purpose of the different time series pretty straight forward.
RAILS: data.to_json
FLEX: JSON.decode(String(srv.lastResult));
The controller simply transforms the Hash return by the model into a json textual representation.
class DataController < ApplicationController
def overview render :text => Hit.overview_data.to_json endend
This is an extract of the method that returns a Hash that contains the time series in an Array.
def Hit.overview_data
result = {}
result[:header] = {:period => {:start => Hit.minimum(:time).to_s(:db), :end => Hit.maximum(:time).to_s(:db)}}
result[:sessions_series] =
{:by_day => Hit.data_serie(Hit.count(:session, :group => :day, :conditions => ‘controller <> “HeartbeatController”’), “sessions by day”) }
result
end
The service is invoked by the following actionscript call
srv.send()
JSON doesn’t support Date objects out of the box, but it’s a nice way to exchange complex data such a Hash and Map between Rails and Flex.