I have a problem with actioncable. I have two channels ( Notification and Post) but only Notification stream data to received method and not Post .
PostChannel look like this =>
class PostChannel < ApplicationCable::Channel
def subscribed
stream_from "post_channel__user_#{current_user.id}"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
PostBroadcastJob looks like this =>
class PostBroadcastJob < ApplicationJob
queue_as :default
def perform(match)
ActionCable.server.broadcast "post_channel_user_#{match.user_id}", match: render_matching(match)
end
private
def render_matching(match)
ApplicationController.renderer.render(partial: 'match/match', locals: { match: match })
end
end
Where I call the job looks like this =>def create
if params[:remotipart_submitted]
respond_to do |f|
@post = current_user.posts.create(post_params)
@ma = Post.matching(@post.Heure,@post.Date,@post.type_activite_id).second
if @ma.nil?
puts " Aucun match"
else
match=@ma
PostBroadcastJob.perform_later(match)
end
f.html { redirect_to user_url(current_user)}
f.js
end
else
flash[:danger]= "nooooooo"
end
end
And my coffe file looks like this => `App.post = App.cable.subscriptions.create "PostChannel", connected: ->
Called when the subscription is ready for use on the server
disconnected: ->
Called when the subscription has been terminated by the server
received: (match) ->
Called when there's incoming data on the websocket for this channel
$('#notificationList').prepend "okok #{match}"`
Results => [ActiveJob] Enqueued NotificationBroadcastJob (Job ID: 59cf14ec-4f76-4b7d-af80-b0bcf6c65986) to Async(default) with arguments: 9, #<GlobalID:0xe483670 @uri=#<URI::GID gid://see-u/Notification/89>>
Notification Load (0.0ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."id" = ? LIMIT ? [["id", 89], ["LIMIT", 1]]
Post Load (1.0ms) SELECT "posts".* FROM "posts" WHERE (Heure BETWEEN '2000-01-01 10:54:00 UTC' AND '2000-01-01 12:54:00 UTC' AND Date = '2017-06-27' AND type_activite_id = '9') ORDER BY "posts"."created_at" DESC LIMIT ? OFFSET ? [["LIMIT", 1], ["OFFSET", 1]]
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] Performing NotificationBroadcastJob from Async(default) with arguments: 9, #<GlobalID:0xe461668 @uri=#<URI::GID gid://see-u/Notification/89>>
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] Relationship Load (0.0ms) Select followed_id from relationships where follower_id =10
Rendered match/_match.html.erb (0.0ms)
[ActionCable] Broadcasting to post_channel_user_8: {:match=>"kklklkklkllklklklk"}
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] Rendered notifications/_counter.erb (4.0ms)
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 10], ["LIMIT", 1]]
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] Rendered notifications/_notification.html.erb (3.0ms)
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] [ActionCable] Broadcasting to notification_channel_user_7: {:counter=>"<li class=\"zoome\">\n <img src=\"/assets/alarm-3bb640e80c366ebf278c6ed6d5cc214cefed0b62e6af95d3436dc438b5e6a250.png\" alt=\"Alarm\" />\n <span id=\"notification-counter\">9</span>\n</li>", :notification=>"<li style=\"text-decoration: none;border-bottom: 1px dotted gray;\">\n\n<div class=\"row\" style=\"margin-bottom: 0px\">\n <span class=\"col s2\" style=\"margin-top: 23px\">\n\n\n <img height=\"55\" width=\"55\" src=\"/system/users/avatars/000/000/010/thumb/boir2.jpg?1491145350\" alt=\"Boir2\" />\n\n\n </span>\n\n <span class=\"col s10\" style=\"margin-top: 15px\"> <a style=\"color: crimson;font-size: 13px\" href=\"/users/10\">Nouvelle activité proposée par Ng</a></span>\n\n\n\n</div>\n\n</li>"}
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] Rendered notifications/_counter.erb (85.0ms)
Rendering posts/create.js.erb
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] Rendered notifications/_notification.html.erb (0.0ms)
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] [ActionCable] Broadcasting to notification_channel_user_8: {:counter=>"<li class=\"zoome\">\n <img src=\"/assets/alarm-3bb640e80c366ebf278c6ed6d5cc214cefed0b62e6af95d3436dc438b5e6a250.png\" alt=\"Alarm\" />\n <span id=\"notification-counter\">9</span>\n</li>", :notification=>"<li style=\"text-decoration: none;border-bottom: 1px dotted gray;\">\n\n<div class=\"row\" style=\"margin-bottom: 0px\">\n <span class=\"col s2\" style=\"margin-top: 23px\">\n\n\n <img height=\"55\" width=\"55\" src=\"/system/users/avatars/000/000/010/thumb/boir2.jpg?1491145350\" alt=\"Boir2\" />\n\n\n </span>\n\n <span class=\"col s10\" style=\"margin-top: 15px\"> <a style=\"color: crimson;font-size: 13px\" href=\"/users/10\">Nouvelle activité proposée par Ng</a></span>\n\n\n\n</div>\n\n</li>"}
[ActiveJob] [NotificationBroadcastJob] [59cf14ec-4f76-4b7d-af80-b0bcf6c65986] Performed NotificationBroadcastJob from Async(default) in 1075.4ms
NotificationsChannel transmitting {"counter"=>"<li class=\"zoome\">\n <img src=\"/assets/alarm-3bb640e80c366ebf278c6ed6d5cc214cefed0b62e6af95d3436dc438b5e6a250.png\" alt=\"Alarm\" />\n <span id=\"notification-counter\">9</span>\n</li>", "notification"=>"<li style=\"text-decoration: none;border-bottom: 1px dotted gray;\">\n\n<d... (via streamed from notification_channel_user_8)
Rendered posts/_post.html.erb (19.5ms)
Rendered posts/create.js.erb (40.4ms)
Completed 200 OK in 3594ms (Views: 722.0ms | ActiveRecord: 205.7ms)
Thanks you to all for your help