Skip to content

Instantly share code, notes, and snippets.

@andys
Last active December 15, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andys/5217920 to your computer and use it in GitHub Desktop.
Save andys/5217920 to your computer and use it in GitHub Desktop.
example of filtering scope in controller
class PlayersController < ActiveController::Base
before_filter :player_scope, except: :create
def index
respond_with(@players = @scope.all)
end
def show
respond_with(@player = @scope.find(params[:id])
end
protected
def player_scope
@scope = if params[:game_id]
Game.find(params[:game_id]).players
else
Player
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment