class V1::PlayersController
Controller for players
-
Renders a list of all players
-
Renders one player
-
Creates a new player
-
Updates a player
-
Deletes a player
-
Serializes a Player using V1::PlayerSerializer
Public Instance Methods
create()
click to toggle source
Create a player
-
Request
-
:name
- player name
-
-
Response
-
serialized Player or HTTP error
-
# File app/controllers/v1/players_controller.rb, line 37 def create @player = Player.new(player_params) if @player.save render json: @player, status: :created, location: @player else render json: {errors: @player.errors}, status: :unprocessable_entity end end
destroy()
click to toggle source
Delete a player A player in a match or on a team may not be deleted.
-
Params
-
:id
- player id
-
-
Response
-
:no_content
or HTTP error
-
# File app/controllers/v1/players_controller.rb, line 69 def destroy if @player.destroy head :no_content else render json: {errors: @player.errors}, status: :unprocessable_entity end end
index()
click to toggle source
Get a list of all players, sorted by player name
-
Response
-
serialized array of players
-
# File app/controllers/v1/players_controller.rb, line 18 def index @players = Player.order 'lower(name)' render json: @players, serializer: V1::ApplicationArraySerializer end
show()
click to toggle source
Get a particular player
-
Params
-
:id
- player id
-
-
Response
-
serialized Player
-
# File app/controllers/v1/players_controller.rb, line 28 def show render json: @player end
update()
click to toggle source
Update a player
-
Params
-
:id
- player id
-
-
Request
-
:name
- different player name
-
-
Response
-
serialized Player or HTTP error
-
# File app/controllers/v1/players_controller.rb, line 54 def update if @player.update(player_params) render json: @player, status: :ok else render json: {errors: @player.errors}, status: :unprocessable_entity end end