Created
April 17, 2009 20:56
-
-
Save abloom/97249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
helper :all # include all helpers, all the time | |
protect_from_forgery # See ActionController::RequestForgeryProtection for details | |
rescue_from ActiveRecord::RecordNotFound do |e| | |
logger.error e.message | |
render_404 | |
end | |
protected | |
def render_404 | |
render :file => "#{Rails.public_path}/404.html", :status => 404 | |
end | |
end | |
################### | |
class TeamsController < ApplicationController | |
def show | |
render :text => params[:team_name] | |
end | |
def index | |
render :text => "Teams#Index" | |
end | |
end | |
################### | |
class PlayersController < ApplicationController | |
before_filter :load_team | |
def show | |
render :text => "Player #{params[:id]} for #{@team}" | |
end | |
def index | |
render :text => "Players for #{@team}" | |
end | |
private | |
def load_team | |
@team = params[:team_name] # this should be Team.find_by_name(params[:team_name]) | |
raise ActiveRecord::RecordNotFound unless @team | |
end | |
end | |
####################### | |
ActionController::Routing::Routes.draw do |map| | |
map.root :controller => "teams", :action => "index" | |
map.with_options(:path_prefix => ":team_name") do |team_name| | |
team_name.root :controller => "teams", :action => "show" | |
team_name.resources :players | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment