In this second part of a two-part series, we'll finish creating reports that can be accessed via the Internet. This article is excerpted from chapter 5 of the book Practical Reporting with Ruby and Rails, written by David Berube (Apress; ISBN: 1590599330).
Building Reports Accessible from the Internet - Graphical Reporting with Rails (Page 3 of 5 )
Although a lot of web reporting is textual, as in the previous example, it's also possible to do graphical reporting with Rails. To demonstrate, let's re-create the team performance report presented at the end of Chapter 4. However, instead of using Gruff to create reports, you will use a Flash charting application. The advantage of using a Flash solution is that it allows for interactivity. For example, you can create tool tips that report exact values when users move their mouse over an area of the graph.
First, let's create a Rails project for the application:
For this example, you'll use a project called Open Flash Chart. It's open source, unlike many other Flash charting components, so you can use it on any size project without paying licensing fees. Obtain Open Flash Chart from http://teethgrinder.co.uk/open-flash-chart/. Unzip it into a temporary directory. Next, copy the open-flash-chart.swf file from the root of the ZIP file into a new directory into your Rails application: public/flash.
You'll also use the Flash Object plug-in, which helps you include Flash objects in your views. Install this plug-in using the following command:
For this example, you will use the players_4 database from Chapter 3, so you will need to edit your config/database.yml file to look something like Listing 5-9.
Listing 5-9.Database Configuration File for the Graphical Report (config/database.yml)
As in the previous example, you're creating only a development environment at this point, so you can safely ignore the other two database connection settings for testing and production.
Place the code shown in Listing 5-10 in config/routes.rb.