Class: ConcertoHardware::PlayersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/concerto_hardware/players_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#destroyObject

DELETE /players/1 DELETE /players/1.json



76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/concerto_hardware/players_controller.rb', line 76

def destroy
  @player = Player.find(params[:id])
  auth!
  @player.destroy

  respond_to do |format|
    format.html { redirect_to hardware.players_url }
    format.json { head :no_content }
  end
end

#editObject

GET /players/1/edit



52
53
54
55
# File 'app/controllers/concerto_hardware/players_controller.rb', line 52

def edit
  @player = Player.find(params[:id])
  auth!
end

#indexObject

GET /players GET /players.json



8
9
10
11
12
13
14
15
16
# File 'app/controllers/concerto_hardware/players_controller.rb', line 8

def index
  @players = Player.all
  auth!

  respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @players }
  end
end

#showObject

GET /players/1 GET /players/1.json GET /players/by_screen/2(.json) GET /players/current(.json)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/concerto_hardware/players_controller.rb', line 22

def show
  if params.has_key? :screen_id
    screen_id = params[:screen_id]
    @player = ConcertoHardware::Player.find_by_screen_id!(screen_id)
  elsif params.has_key? :id
    @player = Player.find(params[:id])
  else # Return data about the logged-in screen
    if current_screen.nil?
      raise ActiveRecord::RecordNotFound, "Couldn't find an authenticated screen."
    else
      @player = Player.find_by_screen_id!(current_screen.id)
      @player.ip_address = request.remote_ip if @player
    end
  end
  auth!

  @player.save if @player.ip_address_changed?

  respond_to do |format|
    format.html # show.html.erb
    format.json {
      render :json => @player.to_json(
        :include => { :screen => { :only => :name } },
        :methods => [:time_zone]
      )
    }
  end
end

#updateObject

PUT /players/1 PUT /players/1.json



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/concerto_hardware/players_controller.rb', line 59

def update
  @player = Player.find(params[:id])
  auth!

  respond_to do |format|
    if @player.update_attributes(player_params)
      format.html { redirect_to [hardware, @player], :notice => 'Player was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render :action => "edit" }
      format.json { render :json => @player.errors, :status => :unprocessable_entity }
    end
  end
end