Skip to content

Commit

Permalink
Actioncable : broadcast。
Browse files Browse the repository at this point in the history
  • Loading branch information
keikun17 committed May 2, 2016
1 parent 444f9e1 commit 3486550
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions action_cable.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Action Cable


## To broadcast

`ActionCable.server.broadcast(channel, args)`

Ex.
```ruby
class UserGamesChannel < ApplicationCable::Channel
def subscribed
stream_from "user_games-#{current_user.id}"
end

def add_game(data)
game = Game.find_by(name: data['game'])
current_user.games << game
ActionCable.server.broadcast "user_games-#{current_user.id}",
games: current_user.games.map(&:name),
type: 'GAME_ADDED'
end
```

---

## Minimum setup required to get action cable working on Rails

### Action Cable has three required configurations:
Expand Down

0 comments on commit 3486550

Please sign in to comment.