Skip to content

Commit

Permalink
Add some documentation explaining subscription rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Nov 4, 2015
1 parent 476aca0 commit 1ce0e66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ App.appearance = App.cable.subscriptions.create "AppearanceChannel",
connected: ->
# Called once the subscription has been successfully completed

rejected: ->
# Called when the subscription is rejected by the server

appear: ->
@perform 'appear', appearing_on: @appearingOn()

Expand Down
16 changes: 16 additions & 0 deletions lib/action_cable/channel/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ module Channel
#
# Also note that in this example, current_user is available because it was marked as an identifying attribute on the connection.
# All such identifiers will automatically create a delegation method of the same name on the channel instance.
#
# == Rejecting subscription requests
#
# A channel can reject a subscription request in the #subscribed callback by invoking #reject!
#
# Example:
#
# class ChatChannel < ApplicationCable::Channel
# def subscribed
# @room = Chat::Room[params[:room_number]]
# reject! unless current_user.can_access?(@room)
# end
# end
#
# In this example, the subscription will be rejected if the current_user does not have access to the chat room.
# On the client-side, Channel#rejected callback will get invoked when the server rejects the subscription request.
class Base
include Callbacks
include PeriodicTimers
Expand Down

0 comments on commit 1ce0e66

Please sign in to comment.