Prev | Current Page 132 | Next

David Berube

"Practical Reporting with Ruby and Rails"


Next, let??™s look at the controller (Listing 5-6):
def index
@actors_today = []
@actors_tomorrow = []
Actor.find(:all).each do |actor|
@actors_today << {:actor=>actor,
:bookings=>actor.booking.find(:all,
:conditions=>[
'TO_DAYS(booked_at)=' <<
TO_DAYS(NOW())'])}
@actors_tomorrow << {:actor=>actor,
:bookings=>actor.booking.find(:all,
:conditions=>[
'TO_DAYS(booked_at)=' <<
TO_DAYS(NOW())+1'])}
end
end
The controller has just one action, which represents the main page people will see
when they visit your page. This action prepares two lists of actors for the view: one for
today??™s schedule and another for tomorrow??™s schedule. Each item in the list has two
parts: an actor object representing the actor and a list of bookings for the appropriate
time period.
After this controller is called, the view of the same name is automatically rendered to
the screen by Rails. Specifically, it implicitly calls the render method for you; you can
override this with your own call to the render method, which lets you render a view with
a different name or that is associated with a different controller.


Pages:
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
plac zabaw quady Samsung PS43D490 profesjonalne wizualizacje 3d Battlefield 3 wygraj peb