nNote The reason the raw array of Event values isn??™t passed directly is that you need to call the to_i
method on average_time, since Rails doesn??™t do that for you. This would require knowledge of the controller??™s
internal structure to be embedded in the view, which violates MVC separation. By remapping it into a
new data structure and calling to_i on the average_time method, you can have a controller-agnostic view.
This has the benefit of letting you change the way this data is produced without affecting the view. As long
as the data passed to the view is an array of hashes with the appropriate values, it should work.
Finally, a respond_to block is used to provide varying results depending on which format
is called. For example, the URL http://localhost:3000/performance/5/1 will use the
HTML format, since that??™s the default format specified in routes.rb.
The first format is HTML. This is the code that is called by the show_report JavaScript
function in the Home controller. Note that it disables the layout if it??™s being called by an
Ajax call.
Pages:
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161