Skip to content

Instantly share code, notes, and snippets.

@abloom
Created April 20, 2009 19:10
Show Gist options
  • Save abloom/98681 to your computer and use it in GitHub Desktop.
Save abloom/98681 to your computer and use it in GitHub Desktop.
ActionController::Routing::Routes.draw do |map|
map.resources :fans
map.resources :league_players
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'new'
map.check '/check', :controller => 'sessions', :action => 'create'
map.resource :session
map.with_options(:path_prefix => ":slug") do |slug|
slug.root :controller => "teams", :action => "show"
slug.resources :players
slug.resources :leagues
slug.resources :games, :member => { :edit_stats => :any }
slug.resources :admins
slug.resources :users
slug.resources :game_players
end
map.register '/register', :controller => 'users', :action => 'create'
map.signup '/signup', :controller => 'users', :action => 'new'
map.resources :field_positions
map.resources :pictures
map.resources :game_players
map.resources :weather_conditions
map.resources :game_types
map.resources :outcomes
map.resources :games
map.resources :location_types
map.resources :sponsors
map.resources :locations
map.resources :levels
map.resources :leagues
map.resources :player_types
map.resources :players
map.resources :age_groups
map.resources :teams
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
#####################################
class GamesController < ApplicationController
before_filter :load_team
# GET /games
# GET /games.xml
def index
@games = Game.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @games }
end
end
# GET /games/1
# GET /games/1.xml
def show
@game = Game.find(params[:id])
@league = League.find(@game.league_id)
@team = Team.first(:conditions => ["id = ?", @league.team_id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @game }
end
end
# GET /games/new
# GET /games/new.xml
def new
@game = Game.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @game }
end
end
# GET /games/1/edit
def edit
@game = Game.find(params[:id])
end
def edit_stats
@game = Game.find(params[:id])
@game_player = GamePlayer.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @game_player }
end
end
# POST /games
# POST /games.xml
def create
@game = Game.new(params[:game])
respond_to do |format|
if @game.save
flash[:notice] = 'Game was successfully created.'
@league = League.find(@game.league_id)
@team = Team.find(@league.team_id)
format.html { redirect_to("/#{@team.slug}/games/#{@game.to_param}") }
format.xml { render :xml => @game, :status => :created, :location => @game }
else
format.html { render :action => "new" }
format.xml { render :xml => @game.errors, :status => :unprocessable_entity }
end
end
end
# PUT /games/1
# PUT /games/1.xml
def update
@game = Game.find(params[:id])
respond_to do |format|
if @game.update_attributes(params[:game])
flash[:notice] = 'Game was successfully updated.'
@league = League.find(@game.league_id)
@team = Team.find(@league.team_id)
format.html { redirect_to("/#{@team.slug}/games/#{@game.to_param}") }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @game.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /games/1
# DELETE /games/1.xml
def destroy
@game = Game.find(params[:id])
@league = League.find(@game.league_id)
@game.destroy
respond_to do |format|
format.html { redirect_to(games_path) }
format.xml { head :ok }
end
end
private
def load_team
@team = Team.find_by_slug(params[:slug])
raise ActiveRecord::RecordNotFound unless @team
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment