| Players | # Players table in database | |
| id | ||
| name | ||
| character_class | # spartan or elite | |
| Games | # Games table in database | |
| id | ||
| player_id | # player these game stats are for | |
| kills | # total kills in the game | |
| deaths | # total deaths in the game | |
| level | # name of the game level (eg, Zanzibar) | |
| game_type | # name of the game type (eg, Free For All) |
class Player < ActiveRecord::Base
has_many :games
end
class Game < ActiveRecord::Base
belongs_to :player
end
class HaloController < ApplicationController
def allPlayers
@players = Player.find(:all);
end
def player
@player = Player.find(params[:id]);
end
end
<!-- NOTE: Your code MUST validate, even though this sample code doesn't --> <h1>All Halo Players</h1> <ul> <% @players.each do |player| %> <li><%= link_to h(player.name), :action => "player", :id => player.id %></li> <% end %> </ul>
<!-- NOTE: Your code MUST validate, even though this sample code doesn't --> <pre> <h3>Name:</h3> <%= h(@player.name) %> <h3>Class:</h3> <%= h(@player.character_class) %> <h3>Inverted:</h3> <%= h(@player.inverted) %> <h3>Games</h3> <table> <tr> <th>Level</th> <th>Game Type</th> <th>Kills</th> <th>Deaths</th> </tr> <% @player.games.each do |game| %> <tr> <td><%= h(game.level) %></td> <td><%= h(game.game_type) %></td> <td><%= h(game.kills) %></td> <td><%= h(game.deaths) %></td> </tr> <% end %> </table>
h(player.name)
h player.name
i = i + 1
i = i + 1;