Prev | Current Page 226 | Next

David Berube

"Practical Reporting with Ruby and Rails"

each do |user|%>
<% meeting_count = user.meetings.count
next if meeting_count==0 or !user.reward %>
<%=user.last_name%>, <%=user.first_name%>
<%=meeting_count%>
<%=user.reward.description%>
<%end%>



For each user, you add a row to the table that contains the name of the user, the total
amount of meetings that salesperson had, and the name of the reward, if any. The loop
calls meetings.count for each row and skips the users without any meetings. You might
want to include users without any meetings; in which case, you can easily delete the next
if meeting_count==0 line.
INCREASING DATABASE QUERY PERFORMANCE
For this chapter??™s example, you??™ll probably find that the database queries do not take nearly as long to
run as the html2ps and ps2pdf calls, so further optimization is probably unnecessary. However, this
won??™t always be the case. If either the meetings or the users table were much larger, or if you had a
more complicated query with more relationships, you might need to make the queries go faster.


Pages:
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
prezenty mieszkanie tychy zasłony Toruń hotele nowoczesne meble