Prev | Current Page 133 | Next

David Berube

"Practical Reporting with Ruby and Rails"


CHAPTER 5 n CONNECTING YOUR REPORTS TO THE WORLD 90
Let??™s take a look at that view (Listing 5-7) next. First, it prints out all of the actors and
their schedule for the day, as follows:

Today's Schedule:


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

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


<%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 %>

<%end%>
<%else%>
Nothing for today!
<%end%>


<%end %>
It loops through each of the actors, prints their name as an h2 element, and then
prints the bookings. It formats the booked_at time for each and prints it, along with the
room name and the project name. The stftime function formats the date into a nice,
human-readable form (see http://ruby-doc.org/core/classes/Time.src/M000297.html for
details).
Then you do a very similar loop for tomorrow??™s schedule. In fact, it??™s identical, except
for the references to @actors_today being replaced with @actors_tomorrow and similar
changes.


Pages:
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
Tim McGraw Drukarnia James Morrison Marie LL Cool J