David Berube
"Practical Reporting with Ruby and Rails"
map { |p|
[p.name, p.id] },
{:include_blank=>false} %>
<%=select 'game', 'id',
[['Click here to select a game',""]] +
@available_games.map { |g|
[g.name, g.id] },
{:include_blank=>false} %>
This code creates two drop-down lists from the data passed from the controller. You
use the map method to turn each array of Active Record objects into the type of array that
the select tag expects: an array of arrays, with the first element as the label and the second
element as the value. This means that for the player Matthew Gifford, for example,
the player??™s name will be displayed in the drop-down list, but the control will actually
have the value 1 (the player??™s ID), which you??™ll use to display the appropriate chart. This
code also puts a blank ???Click here to select . . .??? entry at the top of each drop-down list.
This entry has a label but no value, and it serves to tell the user what to do.
The second div, which has the ID chart, will be used to store the chart. The following
JavaScript makes that happen:
CHAPTER 5 n CONNECTING YOUR REPORTS TO THE WORLD 101