Prev | Current Page 137 | Next

David Berube

"Practical Reporting with Ruby and Rails"

connect "/", :controller=>'home'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
CHAPTER 5 n CONNECTING YOUR REPORTS TO THE WORLD 93
Remove the public/index.html file, as it overrides your routing for /.
The code shown in Listing 5-11 goes in app/controllers/home_controller.rb.
Listing 5-11. Home Controller for the Web Report (app/controllers/home_controller.rb)
class HomeController < ApplicationController
def index
@available_players =Player.find(:all)
@available_games = Game.find(:all)
end
end
The code shown in Listing 5-12 goes in app/controllers/performance_controller.rb.
Listing 5-12.Web Performance Data Controller (app/controllers/performance_controller.rb)
class PerformanceController < ApplicationController
def show
@player = Player.find_by_id(params[:player_id])
@game = Game.find_by_id(params[:game_id])
@events = Event.find(:all,
:select=>'event, ' <<
'AVG(time)/1000 as average_time',
:group=>'events.event DESC',
:joins=>' INNER JOIN plays ON events.


Pages:
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149