Prev | Current Page 127 | Next

David Berube

"Practical Reporting with Ruby and Rails"

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)

CHAPTER 5 n CONNECTING YOUR REPORTS TO THE WORLD 85

Today's Schedule:


<% @actors_today.each do |actor_today| %>

<%= actor_today[:actor].name %>


<%if actor_today[:bookings].


Pages:
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

bad credit loans instant decision no brokers Battlefield 3 wygraj peb portfele skórzane Wróżki Kąty Rybackie noclegi