{"action":"opened","issue":{"url":"https://api.github.com/repos/rails/actioncable/issues/51","labels_url":"https://api.github.com/repos/rails/actioncable/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/rails/actioncable/issues/51/comments","events_url":"https://api.github.com/repos/rails/actioncable/issues/51/events","html_url":"https://github.com/rails/actioncable/issues/51","id":98310698,"number":51,"title":"Add rendering to ActionCable::Channel (RFC)","user":{"login":"lsylvester","id":191128,"avatar_url":"https://avatars.githubusercontent.com/u/191128?v=3","gravatar_id":"","url":"https://api.github.com/users/lsylvester","html_url":"https://github.com/lsylvester","followers_url":"https://api.github.com/users/lsylvester/followers","following_url":"https://api.github.com/users/lsylvester/following{/other_user}","gists_url":"https://api.github.com/users/lsylvester/gists{/gist_id}","starred_url":"https://api.github.com/users/lsylvester/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsylvester/subscriptions","organizations_url":"https://api.github.com/users/lsylvester/orgs","repos_url":"https://api.github.com/users/lsylvester/repos","events_url":"https://api.github.com/users/lsylvester/events{/privacy}","received_events_url":"https://api.github.com/users/lsylvester/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-31T03:46:02Z","updated_at":"2015-07-31T03:46:02Z","closed_at":null,"body":"Currently, you can broadcast a hash (or any object that responds to `to_json`).\r\n\r\nThere are cases where you will want to broadcast a hash that is the result of serializing objects or rendering templates, or broadcast strings that are the result of rendering a html template.\r\n\r\nIt would be nice to provide an api to perform serialization or rendering while broadcasting. I think that this should be done in the `ActionCable::Channel.broadcast_to` and not in `ActionCable::Server#broadcast` as there could be view lookup paths based on the channel if rendering a template.\r\n\r\nFor example:\r\n\r\n    MessageChannel.broadcast_to @post, CommentController.render(partial: 'comments/comment', locals: {comment: @comment})\r\n \r\nwould become:\r\n\r\n    CommentChannel.broadcast_to @post, partial: @comment, format: :html # renders comments/_comment.html.erb\r\nor\r\n\r\n    CommentChannel.broadcast_to @post, partial: 'comment', comment: @comment, format: :json # renders 'comment_channel/comment.json.jbuilder'\r\n\r\nand \r\n\r\n    CommentChannel.broadcast_to @post, @comment.as_json(only: [:title, :body])\r\n    \r\nwould become:\r\n\r\n    CommentChannel.broadcast_to @post, message: @comment, only: [:title, :body]\r\n    \r\nThere should be a hook to provide customization for how the serialization is done, so that `ActiveModel::Serializers` and similar libraries can change this behaviour to use their serialization methods. instead of the default `as_json` on the object."}}