diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2015-11-04 17:40:53 -0600 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2015-11-04 17:42:34 -0600 |
commit | 1ce0e66f090631f5113cb844be32b2b7fe4dc88e (patch) | |
tree | 8ebac494bc23e5248558dbcabff0cc62ba48cc49 /lib/action_cable/channel | |
parent | 476aca0967730360c31bc9aa5c08cf6aa7c0c9fe (diff) | |
download | rails-1ce0e66f090631f5113cb844be32b2b7fe4dc88e.tar.gz rails-1ce0e66f090631f5113cb844be32b2b7fe4dc88e.tar.bz2 rails-1ce0e66f090631f5113cb844be32b2b7fe4dc88e.zip |
Add some documentation explaining subscription rejection
Diffstat (limited to 'lib/action_cable/channel')
-rw-r--r-- | lib/action_cable/channel/base.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index 8bfb74fa89..66d60d7e99 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -66,6 +66,22 @@ module ActionCable # # 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 |