Ruby-on-Rails
  Home arrow Ruby-on-Rails arrow Building Reports Accessible from the Inter...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
RUBY-ON-RAILS

Building Reports Accessible from the Internet
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2010-03-26

    Table of Contents:
  • Building Reports Accessible from the Internet
  • Examining the We b Report Application
  • Graphical Reporting with Rails
  • Creating the Models for the Graphical Report
  • Examining the Graphical Reporting Application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building Reports Accessible from the Internet


    (Page 1 of 5 )

    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).

     Creating the Controller for the Web Report

    The controller will respond to actions of the user by taking data from the model and presenting it via your views. The controller is named home, since you will have just one page. Create the app/controllers/home_controller.rb file with the code shown in Listing 5-6.

    Listing 5-6. Home Controller for the Web Report (app/controllers/home_controller.rb)

    class HomeController < ApplicationController
      def index
        @actors_today = []
        @actors_tomorrow = []
        Actor.find(:all).each do |actor|

          @actors_today << {:actor=>actor,

                            :bookings => actor.bookings.find(:all,
                               :conditions => [
                               'TO_DAYS(booked_at)=' <<
                              
    'TO_DAYS(NOW())'])}
          @actors_tomorrow << {:actor=>actor,
                            :bookings => actor.bookings.find(:all,
                               :conditions => [
                               'TO_DAYS(booked_at)=' <<
                                'TO_DAYS(NOW())+1'])}
        end
      end
    end

    This controller has just one action: index, which displays the bookings for today and tomorrow.

    Creating the View for the Web Report

    Next, let's create a view that actually displays this data, as shown in Listing 5-7.

    Listing 5-7. The Single View for the Actor Scheduling Application (app/views/home/ index.rhtml)

    <style>
      body { font-family: sans-serif }
      h2 { margin-left: 10pt;}
      p { margin-left: 10pt; }
    </style>

    <h1>Today's Schedule:</h1>

    <% @actors_today.each do |actor_today| %>
        <h2><%= actor_today[:actor].name %></h2>
        <p><%if actor_today[:bookings].length > 0 %>
                   
    actor_today[:bookings].each do |b|
                                <%=b.booked_at.strftime('%I:%m%p') %>
                                <%=b.room.name %>,
                                <%=b.project.name %><br>
                   <%end%>
           <%else%>
                                Nothing for today!
           <%end%>
        </p>

    <% end %>

      <h1>Tomorrow's Schedule:</h1>

    <% @actors_tomorrow.each do |actor_tomorrow| %>
        <h2><%= actor_tomorrow[:actor].name %></h2>
        <p><%if actor_tomorrow[:bookings].length > 0 %> 
                   
    actor_tomorrow [:bookings].each do |b|
                             <%=b.booked_at.strftime('%I:%m%p') %>,
                             <%=b.room.name %>,
                             <%=b.project.name %<br>
                    <%end%>
           <%else%>
                             Nothing for tomorrow!
           <%end%>

    <% end %>

    Save this file as app/views/home/index.rhtml.

    Now you need just one more piece: a layout, which is used as a template. In other words, the view is displayed inside the layout. Listing 5-8 shows the layout.

    Listing 5-8. Layout for the Actor Schedule View (app/views/layouts/application.rhtml)

    <html>
      <head>
       
    <title>Actor Schedule Report</title> 
      </head>
      <body>
       
    <%= yield %>
      </body>
    </html>

    Save this as app/views/layouts/application.rhtml. This layout will be used automatically for all pages in the application by default. You can set up a layout for just one controller, and you can also manually override layouts for a given action.

    At this point, the application is complete.

    More Ruby-on-Rails Articles
    More By Apress Publishing


     

    RUBY-ON-RAILS ARTICLES

    - Application Deployment with Capistrano
    - Deploying an Application to the Server
    - Secure Application Deployment with Ruby on R...
    - Installing the Database for Application Depl...
    - Application Deployment
    - Recording Acceptance Tests
    - Commands for Acceptance Testing
    - Acceptance Testing
    - Checkout and Order Processing: the User Side
    - Checkout and Order Processing: the Administr...
    - Online Order Processing: Using PayPal
    - Order and Payment Handling for an Ecommerce ...
    - Checkout and Order Processing for an Ecommer...
    - Getting Text and Currency Working for Multip...
    - Translating a Site for Multiple Language Sup...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek