Prev | Current Page 321 | Next

David Berube

"Practical Reporting with Ruby and Rails"

By separating the data from the presentation, as you??™ve done here, you can
change the way the data is graphed without changing the controller.
In this example, you use Ruby??™s built-in max method, which is part of Enumerable, to
find the maximum count. You can use this method on hashes, arrays, or any other
vaguely list-like structure. It might be faster to make an additional query in the database,
but since you likely have only a few records, you use the Ruby built-in method instead.
Generally, you should have database calls only in the controller, but you need to find the
maximum input value because of a quirk in the complex_bar_graph method, which is a
concern of the view only.
The call to max compares each of the element??™s count fields, but you convert them to
an integer before comparing them. This is because Active Record doesn??™t automatically
detect that the field is a string, so it compares them as strings unless you explicitly convert
them.
Summary
Google News is a great news aggregator, which can be used to tap into a worldwide array
of news sources.


Pages:
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333