Last active
December 15, 2015 06:39
-
-
Save andys/5217920 to your computer and use it in GitHub Desktop.
example of filtering scope in controller
This file contains hidden or 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 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