Smart Admin theme 인 간단한 레일 앱을 실행 중입니다. 많이 시도했지만 응용 프로그램에서 Action 케이블을 실행할 수 없습니다.ActionCable이 채널에서만 #subscribe를 호출하지 않습니다. 연결 등록
my_own_channel.rb
class MyOwnChannel < ApplicationCable::Channel
def subscribed
stream_for 'my_own_channel'
end
def unsubscribed; end
end
channel.rb
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.email
end
protected
def find_verified_user
if verified_user = env['warden'].user
verified_user
else
reject_unauthorized_connection
end
end
end
end
../app/assets/javascripts/channels/my_own.js
App.status_monitor = App.cable.subscriptions.create("MyOwnChannel", {
received: function(data) {
alert('Received....');
},
connected: function() {
alert('connected');
},
disconnected: function() {
alert('disconnected now');
}
});
../app/assets/javascripts/cable.js
//= require action_cable
//= require_self
//= require_tree ./channels
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
}).call(this);
이 모든 일을 한 후, 로그에서 나는 스트림을 볼 수 없습니다. 로그에 있음 :
Started GET "/cable" for 127.0.0.1 at 2017-05-19 22:20:36 +0630
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2017-05-19 22:20:36 +0630
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
[ActionCable] [[email protected]] Registered connection (abcdefghijklmnopqrstuvwxyz)
스트림이 연결되어 있지 않습니다. 다른 문제는 connection.rb의 connect 메소드가 호출되지만 MyOwnChannel의 subscribe 메소드가 호출되지 않는다는 것입니다. 나는 실종 된 것이 없다는 것을 알고 있으며 routes.rb 파일에 /cable
라우트도 마운트했습니다.
이것을 알아 냈습니까? 그렇지 않다면 브라우저의 JS 콘솔에'App.status_monitor'를 입력하면 어떻게됩니까? –