Created
October 14, 2012 11:21
-
-
Save svs/3888291 to your computer and use it in GitHub Desktop.
nested resources and games 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
# routes.rb | |
... | |
resources :games do | |
resources :players | |
resources :moves | |
end | |
... | |
# players_controller.rb | |
class PlayersController < ApplicationController::Base | |
def create | |
@game = Game.find(params[:game_id]) | |
@player = User.find(:id) | |
@game.add_player(@player) | |
... | |
end | |
... | |
def delete | |
@game = Game.find(params[:game_id]) | |
@player = User.find(:id) | |
@game.remove_player(@player) | |
... | |
end | |
end | |
# moves_controller.rb | |
def create | |
@game = Game.find(params[:game_id]) | |
@game.add_move(params[:move]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment