Class: TalkingStick::RoomsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- TalkingStick::RoomsController
- Defined in:
- app/controllers/talking_stick/rooms_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /rooms.
- #deliver_signals! ⇒ Object
-
#destroy ⇒ Object
DELETE /rooms/1.
-
#edit ⇒ Object
GET /rooms/1/edit.
-
#index ⇒ Object
GET /rooms.
-
#new ⇒ Object
GET /rooms/new.
-
#show ⇒ Object
GET /rooms/1.
- #signal ⇒ Object
-
#update ⇒ Object
PATCH/PUT /rooms/1.
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
POST /rooms
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 49 def create @room = Room.new(room_params) if @room.save redirect_to talking_stick.room_path(@room), url: talking_stick.room_path(@room), notice: 'Room was successfully created.' else render :new end end |
#deliver_signals! ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 83 def deliver_signals! return [] unless @participant data = TalkingStick::Signal.where recipient_id: @participant.id # Destroy the signals as we return them, since they have been delivered result = [] data.each do |signal| result << { signal_type: signal.signal_type, sender_guid: signal.sender_guid, recipient_guid: signal.recipient_guid, data: signal.data, room_id: signal.room_id, timestamp: signal.created_at, } end data.delete_all result end |
#destroy ⇒ Object
DELETE /rooms/1
69 70 71 72 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 69 def destroy @room.destroy redirect_to talking_stick.rooms_url, notice: 'Room was successfully destroyed.' end |
#edit ⇒ Object
GET /rooms/1/edit
45 46 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 45 def edit end |
#index ⇒ Object
GET /rooms
9 10 11 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 9 def index @rooms = Room.all end |
#new ⇒ Object
GET /rooms/new
40 41 42 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 40 def new @room = Room.new end |
#show ⇒ Object
GET /rooms/1
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 14 def show @room.last_used = Time.now @room.save if params[:guid] if @participant = Participant.where(guid: params[:guid]).first @participant.last_seen = Time.now @participant.save end end Participant.remove_stale! @room response = { room: @room, participants: @room.participants, signals: deliver_signals!, } respond_to do |format| format.html format.json { render json: response } end end |
#signal ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 74 def signal signal = signal_params signal[:room] = @room signal[:sender] = Participant.where(guid: signal[:sender]).first signal[:recipient] = @participant TalkingStick::Signal.create! signal head 204 end |
#update ⇒ Object
PATCH/PUT /rooms/1
60 61 62 63 64 65 66 |
# File 'app/controllers/talking_stick/rooms_controller.rb', line 60 def update if @room.update(room_params) redirect_to talking_stick.room_path(@room), notice: 'Room was successfully updated.' else render :edit end end |