Prev | Current Page 138 | Next

David Berube

"Practical Reporting with Ruby and Rails"

play_id=plays.id',
:conditions=>["plays.game_id = ? AND plays.player_id= ?",
@game.id, @player.id]
).map { |event|
{:event=>event.event,
:average_time=>event.average_time.to_i}
}
respond_to do |format|
format.html { render :layout=>false if request.xhr? }
format.text { render :layout=>false }
format.xml { render :xml=>{'player'=>@player,
'game'=>@game,
'events'=>@events
}.to_xml(:root=>'player_performance_report',
CHAPTER 5 n CONNECTING YOUR REPORTS TO THE WORLD 94
:skip_types=>true) }
end
end
end
Now you can create the models for the report.
Creating the Models for the Graphical Report
This example will use four models: event (app/models/event.rb), game (app/models/game.rb),
play (app/models/play.rb), and player (app/models/player.rb). Their code is shown in
Listings 5-13 through 5-16.
Listing 5-13. Event Model (app/models/event.rb)
class Event < ActiveRecord::Base
belongs_to :play
end
Listing 5-14. Game Model (app/models/game.rb)
class Game < ActiveRecord::Base
has_many :plays
end
Listing 5-15.


Pages:
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
traktorki ogrodowe terapia magnetyczna Pompy zatapialne mapa Niemiec Wnętrza Poznań